Move Oracle Database Files to Another Disk (Datafiles & Log Files)

Moving Oracle Database Datafiles and Log Files to Another Disk

This guide addresses migrating Oracle Database datafiles and online redo log files from one disk location to another. We'll delve into the provided PL/SQL code, understand its functionality, and offer key considerations for implementation.

Move files between disks

Sample SQL Command

 1set trimspool on wrap off
 2set heading off
 3set verify off
 4set pages 1000 lines 100
 6spool rename.sql
 8select 	'alter database rename file ''' || 
 9	name || ''' to ''' || 
10	replace(name || ''';', '/u01', '/u02')
11from 	v$datafile
14select 	'alter database rename file ''' || 
15	member || ''' to ''' || 
16	replace(member || ''';', '/u01', '/u02')
17from 	v$logfile
20spool off

Understanding the Need for Relocation

Databases often require more storage space as data accumulates. Moving datafiles and log files to a dedicated disk with higher capacity or better performance can optimize database operations.

The Code Breakdown

The provided code snippet generates a script (rename.sql) containing ALTER DATABASE RENAME FILE statements to relocate datafiles and online redo log files. Here's a breakdown:

  1. set trimspool on wrap off: Configures spool file settings for better formatting of the generated script.
  2. set heading off & set verify off: Suppress unnecessary headers and confirmation prompts in the spool file.
  3. set pages 1000 lines 100: Sets spool file pagination to display 100 lines per page (optional customization).
  4. spool rename.sql: Initiates spooling, directing subsequent output to a file named rename.sql.
  5. select ... from: This section constructs the core logic for generating the ALTER DATABASE RENAME FILE statements:
    • 'alter database rename file ''' || member || ''' to ''' || replace(member || ''';', '/u01', '/u02'): Builds the ALTER DATABASE RENAME FILE command dynamically. Let's dissect it further:
      • 'alter database rename file ': Defines the beginning of the statement to rename a database file.
      • || member || ': Uses string concatenation to insert the file name (member) retrieved from the v$datafile (for datafiles) or v$logfile (for log files) view.
      • ''' to ''': Separates the original and new file locations.
      • replace(member || ''';', '/u01', '/u02'): Replaces the existing disk path (/u01) in the file name with the new disk path (/u02).
  6. from v$datafile (or v$logfile): Specifies the data source for file names. The script uses v$datafile for datafiles and potentially v$logfile (in a separate execution) for online redo log files.
  7. /: Terminates the SQL statement.
  8. spool off: Ends spooling, finalizing the rename.sql file.

Key Points

  • This code generates a script containing ALTER DATABASE RENAME FILE statements to relocate datafiles and online redo log files from /u01 to /u02. Modify the script paths to reflect your actual source and destination locations.
  • The script utilizes dynamic SQL to create generic statements applicable to all datafiles or log files within the specified view.
  • Remember to execute the generated rename.sql script after reviewing its contents.


  • Database Outage: While online redo log files can be relocated while the database is open, relocating datafiles generally requires shutting down the database. Consider scheduling downtime to minimize disruption.
  • Permissions: Ensure you have SYSDBA privileges to execute ALTER DATABASE RENAME FILE statements.
  • Datafile Offline: If relocating a datafile associated with a non-system tablespace, take the tablespace offline before executing the ALTER DATABASE RENAME FILE statement.
  • Verification: Validate the script's accuracy before running it. Consider testing the script in a non-production environment.
  • Backup: It's highly recommended to create a full database backup before making any significant datafile modifications.


By following these steps and considering the potential implications, you can effectively migrate Oracle Database datafiles and online redo log files to a new disk location, optimizing storage and potentially improving performance.

Helpful References

Oracle Documentation on ALTER DATABASE RENAME FILE:

Online Redo Log Files:

Posts in this series