The sotware we are going to use is:
Before we can do anything, we must initialize a database cluster. A database cluster is a collection of databases that is managed by a single instance of a running database server.
After initialization, a database cluster will contain a database named postgres, which is meant as a default database for use by utilities, users and third party applications.
In our local pc, a database cluster will be a single directory under which all data will be stored. It is up to you where you choose to store your data.
Sample directory: C:\pgsqldb
To initialize a database cluster, use the command initdb, which is installed with PostgreSQL. The desired file system location of your database cluster is indicated by the -D option, for example:
initdb -D C:\pgsqldb
Tip: As an alternative to the -D option, you can set the environment variable PGDATA. Without -D, the server will try to use the data directory named by the environment variable PGDATA. If that variable is not provided either, it will fail.
Before we can start working with any database, it is necessary to start the database Server:
postgres -D C:\pgsqldb > C:\pgsqldb\logs\logfile.log 2>&1 &
and it can be stopped with this command:
postgres -D C:\pgsqldb stop -m fast
All the steps we have seen before, can be integrated into a single .bat file (I do prefer this way):
@ECHO ON REM The script sets environment variables helpful for PostgreSQL @SET PATH="C:\pgsql\bin";%PATH% @SET PGDATA=C:\pgsqldb @SET PGDATABASE=postgres @SET PGUSER=postgres @SET PGPORT=5432 @SET PGLOCALEDIR=C:\pgsqldb\share\locale REM "C:\pgsql\bin\initdb" "C:\pgsql\bin\pg_ctl" -D "C:\pgsqldb" -l logfile start ECHO "Click enter to stop" pause "C:\pgsql\bin\pg_ctl" -D "C:\pgsqldb" stop -m fast
Note: The line that uses the initdb command, must be executed only one time. After that we can keep it commented. In my case, is taken my windows default user: jorgevs
To create the database, we will use the pgAdmin3 tool
Once its window is open, we will need to configure certain values:
Once we are connected, we will create a sonar user:
the values will be:
Role name: sonar
and now, we create the sonar database:
the values will be:
Owner: sonar (the one we create previously)
Edit <install_directory>/conf/sonar.properties to configure the database settings. Templates are available for every supported database.
Just uncomment and configure the template you need and comment out the lines dedicated to H2
#Example for PostgreSQL sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:postgresql://localhost/sonar
There is nothing to do in this step, since drivers for the supported databases (except Oracle) are already provided. Do not replace the provided drivers; they are the only ones supported.
Note: For Oracle, copy the JDBC driver into <install_directory>/extensions/jdbc-driver/oracle.
The default port is "9000" and the context path is "/". These values can be changed in <install_directory>/conf/sonar.properties:
Execute the following script to start the server:
On Windows: bin/windows-x86-XX/StartSonar.bat Select the StartSonar.bat file according to the JDK you are using (32 or 64 bits).
Now, you can now browse SonarQube at http://localhost:9000 (the default SonarQube administrator credentials are admin / admin).
Note: The first time SonarQube is executed, the database tables will be created.
By default, SonarQube is configured to run on any computer with a simple Java JRE. The first thing to do when installing a production instance is to use a Java JDK and activate the server mode by uncommenting the following line in <install_directory>/conf/wrapper.conf:
wrapper.java.additional.3=-server (do not uncomment in a local pc)
To change the Java JVM used by SonarQube, simply edit <install_directory>/conf/wrapper.conf and update the following line:
You'll need to add those lines to your Maven settings.xml file, so that once you execute your mvn sonar:sonar goal it will be able to register the metrics in your postgreSQL database.
Execute the following maven command into the directory where your application's pom.xml file is located:
Once it has been executed successfully, you'll be able to check your application dashboard in SonarQube: