To use your local database with SonarQube, you need to first decide on which type of supported database you want to use. SonarQube supports various databases like PostgreSQL, MySQL (only until SonarQube 7.8), Oracle, and Microsoft SQL Server.
I'll guide you through setting up SonarQube with a local PostgreSQL database as it's one of the most popular choices:
1. Install PostgreSQL:
sudo apt update
sudo apt install postgresql postgresql-contrib
2. Create the Database and User for SonarQube:
Log in to the PostgreSQL interactive terminal:
sudo -u postgres psql
Now, create a database and a user for SonarQube:
CREATE DATABASE sonarqube; CREATE USER sonar WITH ENCRYPTED PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE sonarqube TO sonar; \q
Replace 'your_password'
with a strong password of your choice.
3. Configure SonarQube to use the PostgreSQL Database:
Edit the SonarQube configuration file:
sudo nano /opt/sonarqube/conf/sonar.properties
Uncomment (remove the #
from the start of the line) and/or modify the following lines to configure the connection to the PostgreSQL database:
sonar.jdbc.username=sonar
sonar.jdbc.password=your_password
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
Again, replace your_password
with the password you set earlier.
4. Restart SonarQube:
After saving the changes, you need to restart the SonarQube service:
sudo systemctl restart sonar.service
SonarQube should now start using the local PostgreSQL database.
Note: Always backup your SonarQube instance and database before making any changes. Using an external database (even if it's local) is better than using the embedded database, especially for production use, as the embedded database is not suitable for production and is only meant for testing and initial setups.