Containerized Sonarqube migration from CentOS to Oracle linux 8

Hi Everyone,

We are migrating our sonarqube from one server (CentOS 7) to other server(Oracle Linux 8)
For migration we are using docker compose which has a dependency on db (postgresql)to connect with the database we are using sonar as user

====
Version on existing server
Sonarqube : 9.8.0-community
Java version - openjdk version “1.8.0_412”
Docker Copmose version - 1.29.2, build 5becea4c
OS version: NAME=“CentOS Linux” VERSION=“7 (Core)”

====
Versions on new server
Sonarqube : 9.8.0-community
Java version - openjdk version “1.8.0_442”
Docker Compose version: v2.32.4
Postgresql - 12
OS version - NAME=“Oracle Linux Server”, VERSION=“8.10”

below is docker compose file

version: "3"

services:
  sonarqube:
     image: sonarqube:9.8.0-community
     depends_on:
        - db
     environment:
        SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
        SONAR_JDBC_USERNAME: <jdbc_user>
        SONAR_JDBC_PASSWORD: <jdbc_password>
     volumes:
        - sonarqube_data:/opt/sonarqube/data
        - sonarqube_extensions:/opt/sonarqube/extensions
        - sonarqube_logs:/opt/sonarqube/logs
     ports:
        - "9000:9000"
  db:
    image: postgres:12
    environment:
      POSTGRES_USER: <user>
      POSTGRES_PASSWORD: <password>
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

volumes:
  sonarqube_data:
  sonarqube_extensions:
  sonarqube_logs:
  postgresql:
  postgresql_data:

Sonarqube is up an running on existing server, however,when we try to replicate same on new server, DB container is coming up but sonarqube container is getting exited after few seconds

Steps:

  1. Based on the docker compose configuration we are trying to create 2 containers (sonarqube and postgres)
  2. Creating a backup of postgresql in .sql and .tar format, do we need to stop container before taking a backup ?
  3. using scp, sending backup of postgresql to other server
  4. restoring backup (.sql)

Note :

  1. we took backup in .sql and .tar and try to restore, in .sql we observed that all the table, keys and other DB objects seems duplicate - how to cleanup and restore fresh ?
  2. but for .tar file restoration, DB restoration is happening, sonarqube container is not coming up afterwards

Below is the error

cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jdk.internal.loader.ClassLoaders$AppClassLoader@5ffd2b27-org.sonar.server.platform.serverid.ServerIdManager’: Initialization of bean failed; nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
2025.02.03 05:40:47 ERROR web[o.s.s.p.Platform] Background initialization failed. Stopping SonarQube

Please suggest, if these are the appropriate migration steps or something is missed ?

Do let us know if you need more information ?

PS: Please share documents, if any

No, it’s not strictly required.

Well, that sounds like the problem if later on, you receive an error that you have duplicate results.

Expected one result (or null) to be returned by selectOne(), but found: 2

Have you made sure that your target database is completely empty before restoring your backup? It sounds like a SonarQube server might have been started against your target DB before you moved the data over, resulting in duplicate entries.

Overall, this is a Postgres administration question rather than a SonarQube one, and you’ll probably be best off referring to Postgres docs for backup/restore features.