How to use symbolic links to move the DB data folder

Are you struggling with performance issues in your Spring, Jakarta EE, or Java EE application?

What if there were a tool that could automatically detect what caused performance issues in your JPA and Hibernate data access layer?

Wouldn’t it be awesome to have such a tool to watch your application and prevent performance issues during development, long before they affect production systems?

Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, Micronaut, or Play Framework.

So, rather than fixing performance issues in your production system on a Saturday night, you are better off using Hypersistence Optimizer to help you prevent those issues so that you can spend your time on the things that you love!

Introduction

In this article, we are going to see how we can use symbolic links to move the DB data folder.

The reason why I needed to move the data folder from the C to the D Windows partition was because the C partition was running out of disk space.

DB data folder

A relational database system requires to store the table records and the index entries on the disk. Besides that, there are other database components that need to be persisted on disk, such as the Redo Log that contains all the changes that were committed by a a given database transaction.

Relational Database Architecture

Because both the data itself (table records and the index entries) and the Redo Log can take a significant amount of space, if you have installed a relational database on your local OS, then it may be that, one day, you’d want to move the database folder to a different partition, to free up space on the partition where the database was installed.

And that was exactly my case. On my laptop, I have installed Oracle, SQL Server, MySQL, and PostgreSQL because I have to use all these databases for running integration tests on my High-Performance Java Persistence, Hypersistence Utils, or Hypersistence Optimizer projects.

How to use symbolic links to move the DB data folder

Because the Oracle data folder had around 10GB, I decided to move it to the D partition to free up space on the C partition.

There are two ways in which you can move the data files in Oracle.

The first option is to shut down the database server, move the data folder to the new location, and start Oracle in MOUNT mode, and use ALTER DATABASE RENAME commands to change the data file locations. You can read more about this option in this article.

The second is to shut down the database server, move the data folder to the new location, and create a symbolic link from the old folder location to the new one.

While the first option is more suitable for a production system, considering that you want the data folder to be persisted on a high-performance SSD drive, the second option is simpler when you need the database for testing purposes.

Therefore, in my case, I executed the following steps:

  1. I shut down every Oracle service.
  2. I moved the content of the c:\app\mihal\product\21c folder to d:\Oracle\21c.
  3. I created a symbolic link from the source folder to the destination one like this:
    mklink /D c:\app\mihal\product\21c d:\Oracle\21c
    
  4. I started every Oracle service.

With the symbolic link in place, now the data is persisted to the D partition, as opposed to the C one.

Conclusion

Symbolic links can provide you with a very simple solution to move the DB data folder from one drive to another.

After I created the symbolic link, the dir command shows me that the c:\app\mihal\product\21c path now points to the d:\Oracle\21c folder and the C partition now has 25.19 GB available disk space.

c:\app\mihal\product>dir
 Volume in drive C is OS

Directory of c:\app\mihal\product

07/20/2024  10:40 AM    <DIR>          .
07/20/2024  10:40 AM    <DIR>          ..
07/20/2024  10:40 AM    <SYMLINKD>     21c [d:\Oracle\21c]
               0 File(s)              0 bytes
               3 Dir(s)  25,192,103,936 bytes free
Transactions and Concurrency Control eBook

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.