I am using the embedded h2 database to store the project information, and as a feature, embedded h2 database won’t release the space even if the corresponding project has been deleted, making the size of sonar.mv.db larger and larger. I wonder if there is a way in sonarqube to release the space. Thank you.
A few key points to keep in mind:
-
The embedded H2 database is not recommended for production use in Sonarqube. It’s intended only for initial evaluation and testing purposes.
-
There is no direct way to shrink or compact the H2 database file, it will grow over time as data is added.
-
The best practice is to migrate to a supported production database like PostgreSQL, Oracle, or MSSQL for proper database management and scaling.
-
If you must continue using the embedded H2 database temporarily, some options to free up space include:
- Purging old analysis data and projects you no longer need
- Reducing the retention period for issues and analyses in the Sonarqube settings
- Backing up and deleting the existing H2 database file, then restoring only the data you need
-
You cannot upgrade Sonarqube versions when using the embedded H2 database. Migrating to a supported database is strongly recommended for any long-term or production use.
In summary, while there’s no easy way to compact the embedded H2 database, the best solution is to migrate to a supported production database ASAP.
This will provide better performance, manageability, and the ability to upgrade Sonarqube in the future.
WRT backing up and deleting the existing H2 database file, then restoring only the data you need.
You might try some obscure hack like
-
Stop the Sonarqube server before performing any database operations.
-
Backup the H2 database:
- Locate the H2 database files in the Sonarqube data directory, in recent versions it’s
$Sonarqube_HOME/data/sonar.mv.db
- Copy the file to a safe location as your backup.
- Locate the H2 database files in the Sonarqube data directory, in recent versions it’s
-
Delete the existing H2 database:
- Remove the “sonar.mv.db” file from the Sonarqube data directory.
-
Start Sonarqube to create a fresh H2 database:
- This will initialize a new, empty H2 database.
- Stop Sonarqube again after the initialization is complete.
-
Restore only the data you need:
- Use the H2 Console or a database tool that supports H2 to connect to both the backup database and the new database.
- Selectively copy the data you want to keep from the backup to the new database using SQL statements.
- Be careful to maintain data integrity and relationships between tables.
Docs = h2database advanced
-
Restart Sonarqube with the restored database.
This is not officially supported by Sonarqube and can be risky.
The embedded H2 database is not recommended for production use, and Sonarqube does not provide built-in tools for partial data restoration.
IMO it’s not worth the effort, both PostgreSQL and MSSQL Express edition are supported and free to use - also commercial.
see
https://docs.sonarsource.com/sonarqube/latest/setup-and-upgrade/installation-requirements/database-requirements/
Thank you for your response
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.