Upgrading from 21 to 22 fails due to database shenanigans

Nextcloud version (eg, 20.0.5): Whichever version the 21-fpm-alpine Docker container uses
Operating system and version (eg, Ubuntu 20.04): Alpine edge
Apache or nginx version (eg, Apache 2.4.25): See above
PHP version (eg, 7.4): See above

The issue you are facing:

Upgrading is usually as simple as pulling a new docker image and running docker-compose up -d. However, that didn’t work from 21-fpm-alpine to 22-fpm-alpine. Running the upgrade command produces this:

# docker exec -u 82 a141cc8041fd ./occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Updating database schema
Updated database
Checking for update of app accessibility in appstore
Checked for update of app "accessibility" in App Store 
Checking for update of app activity in appstore
Checked for update of app "activity" in App Store 
Checking for update of app calendar in appstore
Checked for update of app "calendar" in App Store 
Checking for update of app camerarawpreviews in appstore
Checked for update of app "camerarawpreviews" in App Store 
Checking for update of app cloud_federation_api in appstore
Checked for update of app "cloud_federation_api" in App Store 
Checking for update of app comments in appstore
Checked for update of app "comments" in App Store 
Checking for update of app contacts in appstore
Checked for update of app "contacts" in App Store 
Checking for update of app contactsinteraction in appstore
Checked for update of app "contactsinteraction" in App Store 
Checking for update of app dashboard in appstore
Checked for update of app "dashboard" in App Store 
Checking for update of app dav in appstore
Checked for update of app "dav" in App Store 
Checking for update of app deck in appstore
Checked for update of app "deck" in App Store 
Checking for update of app federatedfilesharing in appstore
Checked for update of app "federatedfilesharing" in App Store 
Checking for update of app federation in appstore
Checked for update of app "federation" in App Store 
Checking for update of app files in appstore
Checked for update of app "files" in App Store 
Checking for update of app files_pdfviewer in appstore
Checked for update of app "files_pdfviewer" in App Store 
Checking for update of app files_rightclick in appstore
Checked for update of app "files_rightclick" in App Store 
Checking for update of app files_sharing in appstore
Checked for update of app "files_sharing" in App Store 
Checking for update of app files_trashbin in appstore
Checked for update of app "files_trashbin" in App Store 
Checking for update of app files_versions in appstore
Checked for update of app "files_versions" in App Store 
Checking for update of app files_videoplayer in appstore
Checked for update of app "files_videoplayer" in App Store 
Checking for update of app firstrunwizard in appstore
Checked for update of app "firstrunwizard" in App Store 
Checking for update of app logreader in appstore
Checked for update of app "logreader" in App Store 
Checking for update of app lookup_server_connector in appstore
Checked for update of app "lookup_server_connector" in App Store 
Checking for update of app maps in appstore
Checked for update of app "maps" in App Store 
Checking for update of app nextcloud_announcements in appstore
Checked for update of app "nextcloud_announcements" in App Store 
Checking for update of app notifications in appstore
Checked for update of app "notifications" in App Store 
Checking for update of app oauth2 in appstore
Checked for update of app "oauth2" in App Store 
Checking for update of app password_policy in appstore
Checked for update of app "password_policy" in App Store 
Checking for update of app photos in appstore
Checked for update of app "photos" in App Store 
Checking for update of app privacy in appstore
Checked for update of app "privacy" in App Store 
Checking for update of app provisioning_api in appstore
Checked for update of app "provisioning_api" in App Store 
Checking for update of app recommendations in appstore
Checked for update of app "recommendations" in App Store 
Checking for update of app serverinfo in appstore
Checked for update of app "serverinfo" in App Store 
Checking for update of app settings in appstore
Checked for update of app "settings" in App Store 
Checking for update of app sharebymail in appstore
Checked for update of app "sharebymail" in App Store 
Checking for update of app support in appstore
Checked for update of app "support" in App Store 
Checking for update of app survey_client in appstore
Checked for update of app "survey_client" in App Store 
Checking for update of app systemtags in appstore
Checked for update of app "systemtags" in App Store 
Checking for update of app text in appstore
Checked for update of app "text" in App Store 
Checking for update of app theming in appstore
Checked for update of app "theming" in App Store 
Checking for update of app twofactor_backupcodes in appstore
Checked for update of app "twofactor_backupcodes" in App Store 
Checking for update of app updatenotification in appstore
Checked for update of app "updatenotification" in App Store 
Checking for update of app user_status in appstore
Checked for update of app "user_status" in App Store 
Checking for update of app viewer in appstore
Checked for update of app "viewer" in App Store 
Checking for update of app weather_status in appstore
Checked for update of app "weather_status" in App Store 
Checking for update of app workflowengine in appstore
Checked for update of app "workflowengine" in App Store 
Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing a query: SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "pg_type_typname_nsp_index"
DETAIL:  Key (typname, typnamespace)=(oc_circles_circle_id_seq, 2200) already exists.
Update failed
Maintenance mode is kept active
Resetting log level
# 

Is this the first time you’ve seen this error? (Y/N): Yes.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'redis' => 
  array (
    'host' => 'nextcloud-redis',
    'password' => 'REDACTED',
    'port' => 6379,
  ),
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'passwordsalt' => 'REDACTED',
  'secret' => 'REDACTED',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'REDACTED',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'pgsql',
  'version' => '21.0.4.1',
  'overwrite.cli.url' => 'https://REDACTED',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'nextcloud-db:5432',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'REDACTED',
  'dbpassword' => 'REDACTED',
  'installed' => true,
  'instanceid' => 'REDACTED',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'loglevel' => 2,
  'maintenance' => false,
  'theme' => '',
);

For the circles app, a unique key is used twice, which makes is less unique. Either go manually through the table and look for the duplicated entry and figure out to delete one. Or file a bug report: Issues · nextcloud/circles · GitHub

If you want to continue, you can disable the circles app (and use Nextcloud without it). Perhaps on enabling again, it installs the new version and fixes your problem.

Perhaps someone more familiar with the circles app can give you more specific advice.

Hello,

This might be an old key from the old times, do you remember the first version of Nextcloud of your setup ?

Not sure, but I’m pretty sure it started as an ownCloud setup and was migrated to Nextcloud when Nextcloud became a thing. It was also migrated into Docker at some point.

For the circles app, a unique key is used twice, which makes it less unique.

Beautifully put. Turns out I don’t actually use Circles for anything important, so I’ll remove it and try the upgrade again.

Are you in NC21 or NC22 currently ?

The 21-fpm-alpine container must mean NC21, I hope.