How To Move Datafiles In Oragle 11gR2
How to Move (Rename) an Oracle Datafile to a New Folder in Oracle 11g
When you accidentally create a datafile in the wrong folder, you can move it to the intended location. Unlike a regular file move, this process in Oracle 11g involves both operating system commands and an update to Oracle’s control file. Follow these steps carefully.
- Backup: Before you begin, ensure you have a current backup of your database or at least the affected tablespace.
- Privileges: You must have the appropriate administrative privileges to perform these operations.
- Environment: The steps differ slightly based on whether you’re dealing with user tablespaces or system-critical tablespaces.
Step 1: Identify the Datafile
Start by confirming the file name and its current location. Connect to SQL*Plus or your preferred Oracle client and run:
SELECT file_name, tablespace_name
FROM dba_data_files;
Review the output to locate the datafile you want to move and note its current path.
Step 2: Prepare the Database
Option A: For Non-Critical (User) Tablespaces
You can take just the affected tablespace offline:
ALTER TABLESPACE your_tablespace_name OFFLINE;
Option B: For System or Critical Tablespaces
For files in the SYSTEM, UNDO, or other critical tablespaces, you need to shut down the database and restart it in MOUNT mode:
SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
Step 3: Move the Datafile at the OS Level
Using your operating system’s file commands, move the datafile from the current location to the new folder. For example, on a UNIX/Linux system:
mv /old_path/your_datafile.dbf /new_path/your_datafile.dbf
- Ensure that the new folder has the proper permissions and enough disk space.
- On Windows, you can use the File Explorer or the
move
command in Command Prompt.
Step 4: Update Oracle’s Control File
After physically moving the file, you must update Oracle’s control file so it knows where to find the datafile. Run the following command in SQL*Plus:
ALTER DATABASE RENAME FILE '/old_path/your_datafile.dbf' TO '/new_path/your_datafile.dbf';
This command tells Oracle that the file has been moved to the new location.
Step 5: Bring the Database or Tablespace Online
If You Took Only the Tablespace Offline:
ALTER TABLESPACE your_tablespace_name ONLINE;
If You Shut Down the Entire Database:
ALTER DATABASE OPEN;
Step 6: Verify the Change
Finally, verify that Oracle recognizes the new location by running:
SELECT file_name, tablespace_name
FROM dba_data_files
WHERE file_name LIKE '%your_datafile.dbf%';
The output should show the new path for the datafile.
Recap
- Identify the datafile: Check the current location and tablespace.
- Prepare the database:
- For user tablespaces, take the tablespace offline.
- For system-critical tablespaces, shut down the database and start it in MOUNT mode.
- Move the file at the OS level: Use OS commands to relocate the file.
- Update the control file: Use
ALTER DATABASE RENAME FILE
to inform Oracle of the new location. - Bring the database or tablespace back online: Open the tablespace or the entire database.
- Verify the move: Confirm the new location with a query.
Comments
Post a Comment