Database Installation

If you have no RDBMS on your machine yet, pick one from the supported ones (scroll down to the "Database" section). In our case, and to show a complete case installation, we have choosen PostgreSQL as our preferred database.

As the database is of critical importance to SonarQube operation, it is highly recommended that you implement a backup and restore policy. As this is dependent not only on the RDBMS engine, but also the system environment, this will not be covered in this guide.

1. Get PostgreSQL

1.1 Visit PostgreSQL download page

1.2 Select the latest version of PostgreSQL and Windows x86-64 as your operating system

1.3 Download the installer, in this example we will get postgresql-12.2-1-windows-x64.exe, to your Downloads folder

2. Install PostgreSQL

2.1 Intall the downloaded file, following the wizard steps

3. Create 'sonar' database

3.1 Use pgAdmin (installed previously next to the database) to open the PostgreSQL console

3.2 Select the postgres database and then select Tools > Query Tool

3.2 Create 'sonar' user

create user sonar with password '<mypassword>';

2.3 Create 'sonar' database

create database sonar with owner sonar;

2.4 Update the pgAdmin database panel to check the database has been created properly

1. Install PostgreSQL (Debian 10 instructions)

1.1 Import the GPG key used for signing packages

sudo apt -y install gnupg2
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

1.2 Add PostgreSQL repository

echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee  /etc/apt/sources.list.d/pgdg.list

1.3 Use the imported linux distribution to install PostgreSQL

sudo apt update
sudo apt -y install postgresql-12 postgresql-client-12

2. Create 'sonar' database

2.1 Access to PostgreSQL console

$ sudo -u postgres psql postgres

2.2 Create 'sonar' user

postgres=# create user sonar with password '<mypassword>';
CREATE ROLE

2.3 Create 'sonar' database

postgres=# create database sonar with owner sonar;
CREATE DATABASE

2.4 List your databases to check 'sonar' has been created properly

postgres=# \list
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |
 sonar     | sonar    | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |
 template0 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

1. Install PostgreSQL (RedHat 8.x instructions)

1.1 Install PostgreSQL

$ sudo yum -y install @postgresql

1.2 Initialize and start PostgreSQL

$ sudo postgresql-setup --initdb
$ service postgresql start

2. Install PostgreSQL (RedHat 7.x instructions)

2.1 Install PostgreSQL

$ sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
$ sudo yum install postgresql12-server

2.2 Initialize and start PostgreSQL

$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
$ systemctl enable postgresql-12
$ systemctl start postgresql-12

3. Change authentication method

3.1 Edit the PosgreSQL configuration file accordingly to the installed version

/var/lib/pgsql/12/data/pg_hba.conf
...
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

4. Create 'sonar' database

4.1 Access to PostgreSQL console

$ sudo -u postgres psql postgres

4.2 Create 'sonar' user

postgres=# create user sonar with password '<mypassword>';
CREATE ROLE

4.3 Create 'sonar' database

postgres=# create database sonar with owner sonar;
CREATE DATABASE

4.4 List your databases to check 'sonar' has been created properly

postgres=# \list
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |
 sonar     | sonar    | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 |
 template0 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)