title: How to backup and restore Sonarqube database in Postgresql
body: <p>I want to rebuild a Sonarqube server with all projects and settings in origin server. The database is Postgresql. But I can't find some documentation for this. </p>
  
  <p>Firstly I tried to backup it in Sonarqube's web UI: Settings -> System -> Backup, then backup it in a xml file. But when I restored it in a new Sonarqube server, all projects in origin server disappeared. It looks that this "backup" is only for settings, not including projects data.</p>
  
  <p>Then I tried to backup database. When building the origin Sonarqube server I've created a database "sonar":</p>
  
  <pre><code>postgres-# create database sonar with owner sonar encoding 'UTF8';
  </code></pre>
  
  <p>So I tried to dump it:</p>
  
  <pre><code>$ sudo su - postgres
  $ pg_dump sonar
  pg_dump: [archiver (db)] connection to database "sonar" failed: FATAL:  database "sonar" does not exist
  </code></pre>
  
  <p>Trying to verify its existence:</p>
  
  <pre><code>$ psql -l
  </code></pre>
  
  <p>But there are only three item: postgres, template0 and template1. Where is the "sonar" database? I also tried to query with user "sonar" but failed:</p>
  
  <pre><code>$ psql -l -U sonar
  psql: FATAL:  Peer authentication failed for user "sonar"
  </code></pre>
  
  <p>So how to rebuild the Sonarqube server with all old projects and settings?</p>