How to move Oracle DB files to a new location

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.

Lots of files...
Lots of files…

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.

select name from v$datafile;
select name from v$datafile;

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.

shutdown immediate
shutdown immediate

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.

mv command
mv 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/“.

rsync -a /opt/oracle/oradata/ /mnt/data/oradata/
rsync -a /opt/oracle/oradata/ /mnt/data/oradata/

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.

mv /opt/oracle/oradata /opt/oracle/oradata.old
mv /opt/oracle/oradata /opt/oracle/oradata.old

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.

ls -l /opt/oracle
ls -l /opt/oracle

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

startup mount
startup mount

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.

alter database rename file
alter database rename file

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

alter database open
alter database open

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):

SELECT OBJECT_TYPE from BI_BIPLATFORM.S_NQ_DSS_OBJECT_TYPES;
SELECT OBJECT_TYPE from BI_BIPLATFORM.S_NQ_DSS_OBJECT_TYPES;

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.

rm -rf /opt/oracle/oradata.old/
rm -rf /opt/oracle/oradata.old/

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

df -m
df -m

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 information contained in this Website is for general information purposes only. We try to keep this information up to date and correct but we make no warranties of any kind about the completeness, accuracy, reliability with respect to the website, the information or the graphics contained on the website for any purpose. Any reliance you place on such information is strictly at your own risk. In no event will we be liable for any loss or damage whatsoever from the use of this Website.

The post How to move Oracle DB files to a new location appeared first on MyBIJourney

All trademarks are properties of their respective owners.
FacebookTwitterPinterestWhatsAppMail