-- Important it's different for NT, read the manual
-- for control file
-- shutdown database;
-- cp control file to new directory
-- change
-- Using svrmgrl and connect internal:
-- shutdown database
shutdown;
-- backup database
-- copy files (don't use mv)
cp -ip /db17/oradata/DBSTAR/DBSTAR_data01.dbf /db13/oradata/DBSTAR/DBSTAR_data01.dbf
cp -ip /db17/oradata/DBSTAR/DBSTAR_ix01.dbf /db13/oradata/DBSTAR/DBSTAR_ix01.dbf
-- check that files were copied successfully
-- startup in mount mode
startup mount;
-- rename files in control file
alter database DBSTAR
rename file '/db17/oradata/DBSTAR/DBSTAR_data01.dbf' to '/db13/oradata/DBSTAR/DBSTAR_data01.dbf';
alter database DBSTAR
rename file '/db17/oradata/DBSTAR/DBSTAR_ix01.dbf' to '/db13/oradata/DBSTAR/DBSTAR_ix01.dbf';
-- alter db open or shutdown/startup
alter database open;
--
shutdown;
startup;
-- query datafile from catalog
select * from dba_data_files;
select * from dba_data_files where file_name like '%data%';
-- query data from one of the tables in the file
select count(*) from payment;
-- check if any processes using old files before they are removed
fuser -u /db17/oradata/DBSTAR/DBSTAR_data01.dbf
fuser -u /db17/oradata/DBSTAR/DBSTAR_ix01.dbf
-- rm old files
rm /db17/oradata/DBSTAR/DBSTAR_data01.dbf
rm /db17/oradata/DBSTAR/DBSTAR_ix01.dbf
----------------------------------------------------------------------------------------------------------------------
In cases where the DBA makes a mistake and names a datafile improperly, or, a data file must be moved for any reason,
it must be renamed. This is accomplished with the ALTER DATABASE RENAME DATAFILE command.
In order to rename a file the database must be mounted but not open.
The general procedure for moving a database file is:
1. Shut down the database
2. Use the operating system to copy the file(s) to their new location. (on UNIX don't move them with the mv command,
use cp or dd)
3. Using SVRMGR issue the CONNECT INTERNAL command to connect to the database.
4. Using SVRMGR MOUNT the database, but don't OPEN it.
startup mount;
5. Issue the ALTER DATABASE command to rename the file.
ALTER DATABASE database name
RENAME FILE 'OLD FILE NAME' TO 'NEW FILE NAME';
6. Shutdown and restart the database.
7. Use SVRMGR or SQLPLUS to look at the view DBA_DATA_FILES to be sure the file is renamed.
8. Delete the old file via the appropriate operating system command.
(Be sure the database is started before you delete the file, if the database is running it will prevent you
from deleting files that are still active on VMS and NT. On UNIX use the "fuser" command against the file to see if
it is active.)
To rename the SYSTEM tablespace or rename multiple tablespaces at one time you must do the following:
1. Shutdown the database, backup.
2. Alter the database mounted but not open.
3. Copy the data file(s) to its new location.
4. Use ALTER DATABASE to rename the datafile(s).
5. Alter the database open.
6. Alter the database to backup the control file.
7. Delete the old file(s).
8. Shutdown and backup the database.
Before making major changes to a database, be sure you have a fallback position. Make backups of the database before you
start and after you finish.
The format for the ALTER DATABASE RENAME DATAFILE command is:
ALTER DATABASE db name
RENAME FILE 'filespec1, filespec2...'
TO 'filespec3, filespec4...'
You must use the full path name for the datafile.
|