Sonarqube Auto cleanup

I am using Sonarqube version 6.7.3 with MySQL as database server.Auto cleanup setting is there in administration settings of sonarqube our database which is MySQL is taking much space. Could you please provide us a solution to apply Auto cleanup in Sonarqube.

As SonarQube 6.x is already long out of support, it will be difficult to get an answer. Best would be to upgrade first your installation to 9.9.x LTS or the current 10.x of SonarQube. Take care on the upgrade path, laboriously you need to upgrade to each of the long-time support releases 6.x - 7.9 - 8.9 - 9.9 (- 10.x).

I have upgraded sonarqube V9.9 LTS. I want to setup auto cleanup/housekeeping policy in SonarQube.
Below configuration will work or i have to update configuration anywhere else.

Please confirm.

For me, this looks alright.
We are using MSSQL and never had issues with database size, neither in the past nor today on our SQL cluster. If you have trouble, you can reduce the number of retained analyses.

Hi,

Just to be clear, housekeeping happens on a project level when the project (branch, not PR) is analyzed. There’s no cron here. To make it kick in, you’ll need to analyze all your projects.

 
HTH,
Ann

1 Like

HI
currently we are executing sonar analysis on Project release basis. Is there any way to delete all the sonar report before 1 year. Because we cannot execute analysis again and again.

Hi,

Housekeeping happens at the end of server-side analysis processing. As I said before, if you want it to kick in, you need to analyze.

 
Ann

Hi team,

I am using Sonarqube 9.9 LTS, I want to clean up the DB storage (Sonar report).
Could you please confirm if i will do the manual cleanup using below process. So DB storage will be cleaned.

Administration: - Project: - management

than i will select the date and delete the report.

So, all the report will be deleted from database or not. Please confirm

Hi,

You don’t delete “reports” from this page. You delete whole projects. And their history. And their issues.

I don’t think this is what you want to do.

As I said, run analysis.

 
Ann

Hi
Thanks for your quick response.

The main problem is that we have more than 2000 sonar reports. Which is taking very high space in server approx 45 GB. And i have to do the cleanup.

As i can not run the analysis for all report.

I want to do the bulk delete from sonarqube just suppose older than 1 year all the reports and analysis should be deleted.

Hi,

Again, you don’t delete “reports” from this page. To be clear, a “report” to me is the result of a single analysis.

From that page you delete whole projects: the latest analysis, and all the issues, and all the issue history, and all the project measures, and the measure history.

If projet deletion is what you want, then that’s the place to achieve it. And it’s not clear to me whether that will result in an immediate reduction in DB usage, or if something else needs to happen to trigger that final cleanout.

 
HTH,
Ann

Hi Ann,

I have deleted the project from SonarQube UI. Using Admin: - Project: - management than selected the project and done the deletion.

I am using MySQL server 5.7. After deleting the project still Database does not release space after project deletion from SonarQube.

Could you please confirm me that how we can do the SonarQube database cleanup.

Hi,

We don’t support MySQL and haven’t for several years.

And double-checking SonarQube 9.9, the Projects Management page doesn’t match your screenshot.

Please migrate to a supported DB engine and upgrade to a supported version of SonarQube. Make sure you perform the post-upgrade steps.

 
Ann

Hi Ann,
I have another server SonarQube 9.9 LTS where we are using Postgres SQL. In this case how we can do the SonarQube DB cleanup.

Hi,

In current versions, the DB-level deletion is synchronous with the deletion from the UI. That wasn’t always the case, but I can’t tell you what version it changed in.

 
HTH,
Ann

Hi Ann
Thanks for your quick response.

Could you please suggest how we do the auto cleanup using SonarQube web Api. As i have check and found that below command. Please confirm if i can used the same.

curl -X POST -u SONARQUBE_TOKEN: SONARQUBE_INSTANCE/api/projects/bulk_delete?lastAnalyzedBefore=2022-05-01

Requirement: - I want to create auto script to delete all the project/analysis older than 2 years without running the analysis again.

Thanks.

Hi,

You need to be aware that that lastAnalyzedBefore only take the main branch into account. So if you’ve got a project where all the action happens on the develop project, you could delete it without meaning to.

Regarding the exact syntax of the command, the best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.

You may also find this guide helpful.

 
HTH,
Ann

Hi Ann,

Could you please confirm on SonarQube 9.9.5 LTS no need to do the DB cleanup from database.

Hi,

You should never need to do any manual intervention directly in the DB for any version of SonarQube.

 
HTH,
Ann