Upgrade from 7.9.1 LTS to 8.9.3 LTS -> Fail to execute CREATE UNIQUE INDEX live_measures_component


I’m trying to update from SonarQube 7.9.1 LTS to 8.9.3 LTS. I’m on Windows and I use an Postgres database. Sadly, the database migration fails:

2021.12.07 13:36:29 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration ended with an exception
org.sonar.server.platform.db.migration.step.MigrationStepExecutionException: Execution of migration step #3545 'Add index on 'metric_uuid' column of 'LIVE_MEASURES' table' failed

The table live measures contains more that 800000 records. A manual execution of the index creation statement shows the following error:

CREATE UNIQUE INDEX live_measures_component ON live_measures (component_uuid, metric_uuid);

FEHLER:  konnte Unique Index „live_measures_component“ nicht erstellen
DETAIL:  Schlüssel (component_uuid, metric_uuid)=(AVU0FlJLF0gdnEyurGvF, 98) ist doppelt vorhanden.
********** Fehler **********

FEHLER: konnte Unique Index „live_measures_component“ nicht erstellen
SQL Status:23505
Detail:Schlüssel (component_uuid, metric_uuid)=(AVU0FlJLF0gdnEyurGvF, 98) ist doppelt vorhanden.

Deleting one of the records that fail the constraint lead to presentaion of the next dataset failing the constraint. So trial and error is not a constructive way to solve this issue, and i also dont know if simple deletion of the vialoating datasets will lead to a semantically correct database.

Here is a Sonar Bug i found for this issue via a similar post in this forum. The workaround described in this bug, namely finding and deleting projects that were last analyzed with SonarCube older than a certain version is not applicable here, as the query provided in the bug to find these projects leads to no records found. As we have more that 800 projects in this installation finding the problemativ projects via clicking through them seems not very clever. So what is the proposed solution to make the upgrade from V7.9.1 to V8.9.3 succeed here?