Converting database type mysql to postgres

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version __: 20.0.6
Operating system and version __: Ubuntu 20.10
Apache or nginx version __: nginx/1.18.0
PHP version __: 7.4.9

The issue you are facing:

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

Steps to replicate it:

  1. sudo -u www-data php /var/www/html/occ db:convert-type --password pass --all-apps pgsql postgres localhost nextcloud_storage

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

<?php
$CONFIG = array (
  'instanceid' => 'xxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'trusted_domains' => 
  array (
    0 => 'cloud.mutabor.su',
    1 => 'onlyoffice.mutabor.su',
  ),
  'trusted_proxies' => '[x.x.x.x]',
  'datadirectory' => '/nextcloud_data/data',
  'auth.bruteforce.protection.enabled' => true,
  'dbtype' => 'mysql',
  'version' => '20.0.6.1',
  'overwrite.cli.url' => 'https://cloud.mutabor.su',
  'dbname' => 'nextcloud_storage',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbschema' => 'public',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'cloud',
  'dbpassword' => 'xxxxxxxxxxxxxxxxxxx',
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  'log_type' => 'file',
  'loglevel' => '1',
  'logdateformat' => 'F d, Y H:i:s',
  'logfile' => '/var/log/nextcloud.log',
  'log.condition' => 
  array (
    'apps' => 
    array (
      0 => 'admin_audit',
    ),
  ),
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0.0,
  ),
  'updater.release.channel' => 'stable',
  'mail_from_address' => 'cloud',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'mutabor.su',
  'mail_smtphost' => 'smtp.yandex.ru',
  'mail_smtpport' => '465',
  'app_install_overwrite' => 
  array (
    0 => 'files_ebookreader',
    1 => 'files_opds',
    2 => 'files_reader',
    3 => 'files_retention',
    4 => 'checksum',
    5 => 'ocdownloader',
    6 => 'weather',
    7 => 'occweb',
  ),
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauth' => 1,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpname' => 'xxxxxxx@mutabor.su',
  'mail_smtppassword' => 'xxxxxxxxxxxxxxxxx',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
);

When i run
sudo -u www-data php /var/www/html/occ db:convert-type --password pass --all-apps pgsql postgres localhost nextcloud_storage
i have

    In AbstractPostgreSQLDriver.php line 60:
                                                                                                                                                     
  An exception occurred while executing 'INSERT INTO "oc_ocdownloader_admin" ("ID", "KEY", "VAL") VALUES(?, ?, ?)' with params ["1", "ProxyUser", "  
  axolotl"]:                                                                                                                                         
                                                                                                                                                     
  SQLSTATE[42703]: Undefined column: 7 ОШИБКА:  столбец "ID" в таблице "oc_ocdownloader_admin" не существует                                         
  LINE 1: INSERT INTO "oc_ocdownloader_admin" ("ID", "KEY", "VAL") VAL...                                                                            
                                               ^                                                                                                     
                                                                                                                                                     

In PDOStatement.php line 129:
                                                                                                              
  SQLSTATE[42703]: Undefined column: 7 ОШИБКА:  столбец "ID" в таблице "oc_ocdownloader_admin" не существует  
  LINE 1: INSERT INTO "oc_ocdownloader_admin" ("ID", "KEY", "VAL") VAL...                                     
                                               ^                                                              
                                                                                                              

In PDOStatement.php line 127:
                                                                                                              
  SQLSTATE[42703]: Undefined column: 7 ОШИБКА:  столбец "ID" в таблице "oc_ocdownloader_admin" не существует  
  LINE 1: INSERT INTO "oc_ocdownloader_admin" ("ID", "KEY", "VAL") VAL...

sudo -u www-data php /var/www/html/occ db:convert-type --password pass --clear-schema pgsql postgres localhost nextcloud_storage doesn’t help, same thing

I’ve tried

sudo su - postgres -c 'psql -d nextcloud_storage -c "DROP TABLE IF EXISTS oc_onlyoffice_filekey;"'

and was getting the same with other tables

After

sudo su - postgres  -c 'psql -d nextcloud_storage -c "DROP TABLE IF EXISTS oc_onlyoffice_filekey, oc_passwords_entity_password, oc_passwords_entity_password_revision, oc_passwords_entity_folder, oc_passwords_entity_folder_revision, oc_passwords_entity_tag, oc_passwords_entity_tag_revision, oc_passwords_relation_password_tag, oc_passwords_entity_share, oc_passwords_entity_session, oc_passwords_entity_keychain, oc_passwords_entity_challenge, oc_passwords_entity_registration;"' && sudo -u www-data php /var/www/html/occ db:convert-type --password pass --all-apps pgsql postgres localhost nextcloud_storage

i have

In AbstractPostgreSQLDriver.php line 51:
                                                                                                                                                    
  An exception occurred while executing 'INSERT INTO "oc_files_antivirus" ("fileid", "check_time") VALUES(?, ?)' with params ["29", "1610251508"]:  
                                                                                                                                                    
  SQLSTATE[23505]: Unique violation: 7 ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности "oc_files_antivirus_pkey"            
  DETAIL:  Ключ "(fileid)=(29)" уже существует.                                                                                                     
                                                                                                                                                    

In PDOStatement.php line 129:
                                                                                                                                          
  SQLSTATE[23505]: Unique violation: 7 ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности "oc_files_antivirus_pkey"  
  DETAIL:  Ключ "(fileid)=(29)" уже существует.                                                                                           
                                                                                                                                          

In PDOStatement.php line 127:
                                                                                                                                          
  SQLSTATE[23505]: Unique violation: 7 ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности "oc_files_antivirus_pkey"  
  DETAIL:  Ключ "(fileid)=(29)" уже существует.

It is end, i do not know what else i can do…