I realised a few days ago that the disk of my Oracle Linux VM only had a few GB left and that I was going to need more space to store additional data. I decided therefore to add a new disk to the VM (click the link to see how I did it) and to move the Oracle database files to the new disk. So let’s see how I did it in this new tutorial.

First I executed the “select name from v$datafile;” command to identify the names and locations of the database files. As you can see in the next screenshot, most of the files were located in the “/opt/oracle/oradata/ORCLCDB/” directory but some of them were in the “/opt/oracle/product/19c/dbhome_1/dbs/” directory.

The idea was to move these datafiles to the new virtual disk. I needed first to shutdown the oracle instance in order to move the files. I used the “shutdown immediate” command to close and dismount the database.

For simplicity, I wanted to have all the datafiles in the same location, so I moved the two files that were initially located in the “/opt/oracle/product/19c/dbhome_1/dbs/” directory to the “/opt/oracle/oradata/ORCLCDB/” directory using the “mv” shell command.

All the datafiles were now located in the “/opt/oracle/oradata/ORCLCDB/” directory. Therefore I used the “rsync -a /opt/oracle/oradata/ /mnt/data/oradata/” shell command to copy the “/opt/oracle/oradata/” directory onto the new disk mounted as “/mnt/data/“.

I decided to rename the original “/opt/oracle/oradata” directory to “/opt/oracle/oradata.old” in order to have a temporary backup of the database files in case something went wrong.

I created a new symbolic link from the “/mnt/data/oradata” directory to “/opt/oracle/oradata” using the “ln -s /mnt/data/oradata /opt/oracle/oradata” shell command. It allowed to keep the original filenames for most of the oracle database datafiles. I checked the result with the “ls -l /opt/oracle” shell command.

I went back to the sqlplus command line interface and restarted the oracle instance using the “startup mount” command.

I renamed the two files that were originally located in the “/opt/oracle/product/19c/dbhome_1/dbs/” folder in order to reflect their new location using the “alter database rename file” sqlplus command.

And finally I opened the database using the “alter database open” sqlplus command.

I decided to test if everything was ok by executing a SELECT statement for one of the tables created during the configuration of OAS (stored in the BI_biplatform.dbf datafile):

And everything went smoothly. I could now remove the “/opt/oracle/oradata.old” backup directory using the “rm -rf /opt/oracle/oradata.old/” shell command.

After that, I checked how much space was available on the virtual disks using the “df -m” shell command.

The original disk now had a bit less than 8 GB available while the new disk had more than 31 GB available. Great, I now had plenty of space for storing my BI data!
Disclaimer
The post How to move Oracle DB files to a new location appeared first on MyBIJourney