Upgrading from 9.0 to 9.1 fails on DB migration with postgresql

  • versions used SonarQube Enterprise upgrading from 9.0 to 9.1
  • error observed
2021.09.21 08:00:43 INFO  web[][o.s.s.p.d.m.DatabaseMigrationImpl] Starting DB Migration and container restart
2021.09.21 08:00:43 INFO  web[][DbMigrations] Executing DB migrations...
2021.09.21 08:00:43 INFO  web[][DbMigrations] #6017 'Migrate portfolios to new tables'...
2021.09.21 08:00:43 ERROR web[][DbMigrations] #6017 'Migrate portfolios to new tables': failure | time=99ms
2021.09.21 08:00:43 ERROR web[][DbMigrations] Executed DB migrations: failure | time=101ms
2021.09.21 08:00:43 ERROR web[][o.s.s.p.d.m.DatabaseMigrationImpl] DB migration failed | time=116ms
2021.09.21 08:00:43 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 #6017 'Migrate portfolios to new tables' failed
       at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:79)
       at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:67)
       at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
       at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:52)
       at org.sonar.server.platform.db.migration.engine.MigrationEngineImpl.execute(MigrationEngineImpl.java:68)
       at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doUpgradeDb(DatabaseMigrationImpl.java:105)
       at org.sonar.server.platform.db.migration.DatabaseMigrationImpl.doDatabaseMigration(DatabaseMigrationImpl.java:80)
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
       at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Failed to migrate views definitions property.
       at org.sonar.server.platform.db.migration.version.v91.MigratePortfoliosToNewTables.execute(MigratePortfoliosToNewTables.java:129)
       at org.sonar.server.platform.db.migration.step.DataChange.execute(DataChange.java:44)
       at org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl.execute(MigrationStepsExecutorImpl.java:75)
       ... 9 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: value too long for type character varying(50)
       at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
       at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
       at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
       at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
       at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
       at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
       at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
       at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
       at org.apache.commons.dbcp2.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:94)
       at org.sonar.server.platform.db.migration.step.UpsertImpl.execute(UpsertImpl.java:66)
       at org.sonar.server.platform.db.migration.version.v91.MigratePortfoliosToNewTables.insertPortfolio(MigratePortfoliosToNewTables.java:176)
       at org.sonar.server.platform.db.migration.version.v91.MigratePortfoliosToNewTables.execute(MigratePortfoliosToNewTables.java:118)
       ... 11 common frames omitted
  • steps to reproduce
    ** Upgrade from SonarQube 9.0 to 9.1 (SonarQube Server / 9.1.0.47736)
    ** Run /setup endpoint
  • potential workaround None so far, am trying to find the offending value so I can potentially truncate it and try to run the migration script again.

Specifically I believe this is the issue in

We have some portfolios composed from multiple tags, some of the resulting strings are way more than the 50 characters set aside from this column in the Postgres database.

                            Table "public.portfolios"
        Column        |          Type           | Collation | Nullable | Default
----------------------+-------------------------+-----------+----------+---------
 uuid                 | character varying(40)   |           | not null |
 kee                  | character varying(400)  |           | not null |
 name                 | character varying(2000) |           | not null |
 description          | character varying(2000) |           |          |
 root_uuid            | character varying(40)   |           | not null |
 parent_uuid          | character varying(40)   |           |          |
 private              | boolean                 |           | not null |
 selection_mode       | character varying(50)   |           | not null |
 selection_expression | character varying(50)   |           |          |
 created_at           | bigint                  |           | not null |
 updated_at           | bigint                  |           | not null |

I could always increase the size of the column myself, however, I don’t think that’s necessarily a good idea for the future.

Thanks for reporting the problem.
We’ll increase the limit in the next release v9.2, which is planned for November: https://jira.sonarsource.com/browse/SONAR-15422

I’d recommend you try to find the offending value as you said, or wait for 9.2 to be released.