nextcloud / nextcloud/server

[Bug]: Conversion of MariaDB to Postgres17 fails on oc_storages_numeric_id_seq sequence

Open
#56,128 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop 30-feedback bug feature: database feature: occ
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

While converting my mariaDB instance to pgsql i get the following exception:

In ExceptionConverter.php line 62:

  An exception occurred while executing a query: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ")"
  LINE 1: ...nextcloud.oc_storages_numeric_id_seq', (SELECT MAX() FROM ))
                                                                       ^


In Exception.php line 24:

  SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ")"
  LINE 1: ...nextcloud.oc_storages_numeric_id_seq', (SELECT MAX() FROM ))
                                                                       ^


In Connection.php line 71:

  SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ")"
  LINE 1: ...nextcloud.oc_storages_numeric_id_seq', (SELECT MAX() FROM ))
                                                                       ^

oc_storages in mysql looks like this:

MariaDB [nextcloud]> select * from oc_storages;
+------------+----------------------------+-----------+--------------+
| numeric_id | id                         | available | last_checked |
+------------+----------------------------+-----------+--------------+
|          1 | home::User1                |         1 |         NULL |
|          3 | home::User2                |         1 |         NULL |
|          4 | local::/var/www/html/data/ |         1 |         NULL |
+------------+----------------------------+-----------+--------------+
3 rows in set (0.001 sec)

and:

MariaDB [nextcloud]> explain oc_storages;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| numeric_id   | bigint(20)  | NO   | PRI | NULL    | auto_increment |
| id           | varchar(64) | YES  | UNI | NULL    |                |
| available    | int(11)     | NO   |     | 1       |                |
| last_checked | int(11)     | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+
4 rows in set (0.001 sec)

the sequence in postgresql exists despite the exception:

nextcloud=# \d nextcloud.oc_storages_numeric_id_seq
               Sequence "nextcloud.oc_storages_numeric_id_seq"
  Type  | Start | Minimum |       Maximum       | Increment | Cycles? | Cache
--------+-------+---------+---------------------+-----------+---------+-------
 bigint |     1 |       1 | 9223372036854775807 |         1 | no      |     1
Owned by: nextcloud.oc_storages.numeric_id

nextcloud=# SELECT * FROM nextcloud.oc_storages_numeric_id_seq;
 last_value | log_cnt | is_called
------------+---------+-----------
          1 |       0 | f
(1 row)
Steps to reproduce

php occ db:convert-type --password="xxxx" pgsql nextcloud nextcloud-psql-primary.nextcloud.svc nextcloud

Expected behavior

have a working PGSQL conversion on the target

Nextcloud Server version

30, 31.0.10, 32.0.1

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report
{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "***REMOVED SENSITIVE VALUE***"
        ],
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "31.0.10.2",
        "overwrite.cli.url": "http:\/\/localhost",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "loglevel": 0,
        "maintenance": false,
        "app_install_overwrite": [
            "occweb",
            "passman",
            "news",
            "files_opds",
            "folderplayer"
        ],
        "theme": "",
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_sendmailmode": "smtp",
        "mail_smtpauth": 1,
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "default_phone_region": "DE",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "password": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        }
    }
}
List of activated Apps

Nextcloud Signing status
No errors have been found.
Nextcloud Logs

Additional info

Running docker image via helm chart, version 31.0.10, also version 30 was affected.
after upgrading nextcloud to version 32.0.1 this issue is still present.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the php occ db:convert-type command and trace the MariaDB-to-PostgreSQL conversion handling for the oc_storages numeric_id sequence. Reproduce the failure using the reported schema and inspect the generated SQL; done means conversion completes successfully and the PostgreSQL sequence is initialized without the invalid MAX() query.

Written by the indexing model from the issue text.

Assessment

Tech stack
mariadb, php, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.