DockerCompose upgrade from 8.9 to 9.9 Postgres DB error

I’m running sonarqube lts-developer 8.9 and want to upgrade to version 9.9. I changed my docker-compose file to look like below. The container upgraded to 9.9 but it defaulted to use the default DB and not the DB I was using previously. I’m getting this Postgres DB error message, please advice, thanks

********** ERROR ************
PostgreSQL Database directory appears to contain a database; Skipping initialization

2023-10-03 17:28:30.943 UTC [1] FATAL: database files are incompatible with server
2023-10-03 17:28:30.943 UTC [1] DETAIL: The data directory was initialized by PostgreSQL version 14, which is not compatible with this version 16.0 (Debian 16.0-1.pgdg120+1).


My Docker-compose.yml file

version: "3.7"

services:
  sonarqube:
    image: sonarqube:lts-developer
    restart: unless-stopped
    depends_on:
      - db

    environment:
      - SONARQUBE_JDBC_USERNAME=xxxxxxxxxx
      - SONARQUBE_JDBC_PASSWORD=xxxxxxxxxx
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/xxxxxxxx
      - SONARQUBE_URL=https://xxxxxxxxxxxxxxxxxxxx.com
    volumes:
      - ./sonarqube/sq/sonarqube_data:/home/sonarqube/data
      - ./sonarqube/sq/sonarqube_extensions:/home/sonarqube/extensions
      - ./sonarqube/sq/sonarqube_logs:/home/sonarqube/logs
      - ./sonarqube/sq/sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
      - ./sonarqube/sq/temp:/var/sonarqube/temp
      - ./sonarqube/sq/data:/var/sonarqube/data
    ports:
      - "9000:9000"

  db:
    image: postgres:latest
    restart: always
    environment:
      - SONARQUBE_JDBC_USERNAME=xxxxxx
      - SONARQUBE_JDBC_PASSWORD=xxxxxx
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/xxxxxxxxxxxx
    volumes:
      - ./db/postgresql:/var/lib/postgresql
      - ./db/postgresql_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  nginx-proxy:
    image: nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"

    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d/
      - ./nginx/certs:/etc/ssl/private
      - ./nginx/certs:/etc/ssl/certs
      - ./sq/logs:/var/log
      - ./sq/logs:/var/log/nginx

Hey there.

As noted in the upgrade notes

  • The deprecated SONARQUBE_JDBC_USERNAME, SONARQUBE_JDBC_PASSWORD, and SONARQUBE_JDBC_URL variables have been removed. See Environment variables for up-to-date configuration variables.

I would revisit this configuration:

You probably need to perform a pg_upgrade or similiar (or pin your Postgres version to 14, instead of using postgres:latest)