Synology DSM NextCloud OCC 错误

最近把nextcloud的版本从12升级到15,PHP也从5.6升级到7.0,提示需要修复一些数据库。

  • 数据库丢失了一些索引。由于给大的数据表添加索引会耗费一些时间,因此程序没有自动对其进行修复。您可以在 Nextcloud 运行时通过命令行手动执行 “occ db:add-missing-indices” 命令修复丢失的索引。索引修复后会大大提高相应表的查询速度。
    • 在数据表 “oc_share” 中无法找到索引 “share_with_index”。
    • 在数据表 “oc_share” 中无法找到索引 “parent_index”。
    • 在数据表 “oc_share” 中无法找到索引 “owner_index”。
    • 在数据表 “oc_share” 中无法找到索引 “initiator_index”。
    • 在数据表 “oc_filecache” 中无法找到索引 “fs_mtime”。
  • 该实例缺失了一些推荐的 PHP 模块。为提高性能和兼容性,我们强烈建议安装它们。
    • imagick
  • 数据库中的一些列由于进行长整型转换而缺失。由于在较大的数据表重改变列类型会耗费一些时间,因此程序没有自动对其更改。您可以通过命令行手动执行 “occ db:convert-filecache-bigint” 命令以应用挂起的更改。该操作需要当整个实例变为离线状态后执行。查阅相关文档以获得更多详情。
    • activity.activity_id
    • activity.object_id
    • activity_mq.mail_id
    • filecache.fileid
    • filecache.storage
    • filecache.parent
    • filecache.mimetype
    • filecache.mimepart
    • filecache.mtime
    • filecache.storage_mtime
    • mimetypes.id
    • storages.numeric_id

结果要用到命令行PHP执行OCC任务时,总是提示类似如下错误:

Stack trace:
#0 /volume1/web/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /volume1/web/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /volume1/web/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /volume1/web/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /volume1/web/nextcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /volume1/web/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Ob in /volume1/web/nextcloud/lib/private/DB/Connection.php on line 64

试了很多办法,但是始终没法搞定,最后在nextcloud的官网讨论区看了一个哥们的解释,似乎明白了怎么回事。

NC 15 OCC Failed to connect to the database

geom

1

1月8日

After searching, testing and reading it is now getting clearer.
The problem I encountered is NOT an NEXTCLOUD issue, but has to do with the confusing (at least for me) PHP handling my Synology Diskstation does (Nextcloud is running on it).
The PHP-CLI uses a different version php.ini file (located in /urs/local/etc/php70/) than the webstation does (located in /volume1/@appstore/WebStation/misc/). So configuring the PHP version for the Webstation does only affect the php.ini from the WebStation which is used to run Nextcloud in the browser. This means that the webupdater could behave different from the occ-script launched via terminal, even if both run PHP 7.0.
To get things work I first need to unterstand this.

The PHP configuring via the GUI of DS > WebStation only affects the PHP-version that is used by the web updater.
The configuration of the PHP-version used by the CLI, to run occ commands needs to be set in the php.ini in the /urs/local/etc/php70/ folder. Most missing modules can easily be enabled by just adding ‘extension = pdo_mysql.so’, … to the php.ini-file (e.g. using midnight commander as root (sudo -i)).

I hope this might help You, when You encounter errors like the following:

Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /volume1/web/nextcloud/lib/private/DB/Connection.php:64

At least on Synology, which a few of us run Nextcloud on, migth help to unterstand whats wrong, and where / how things could be solved.
Happy New Year and happy nextclouding.

意思时群晖使用的webstation管理的php.ini 配置文件只是用于网站的,所以升级怎么都可以跑不会出错。命令行的php用不同的ini文件,需要自己去配置,真是坑爹。

最后解决办法如下:

打开/urs/local/etc/php70/,可以直接vi修改php.ini文件,但是观察了下好像有更好的办法,在conf.d文件夹,新建一个叫nextcloud.ini文件,然后打开ini文件添加一行:

extension = pdo_mysql.so

保存再运行

$ sudo -u http php70 occ db:add-missing-indices

The posix extensions are required – see http://php.net/manual/en/book.posix.php

没有报错了,但是提示缺少extension,那就简单了,依样画葫芦在nextcloud.ini文件再加上缺少的扩展extension。

DiskStation:/usr/local/etc/php70/conf.d$ cat nextcloud.ini
extension = pdo_mysql.so
extension = posix.so

再运行就好了

DiskStation:/volume1/web/nextcloud$ sudo -u http php70 occ db:add-missing-indices
The current PHP memory limit is below the recommended value of 512MB.
Check indices of the share table.
Adding additional share_with index to the share table, this can take some time…
Share table updated successfully.
Adding additional parent index to the share table, this can take some time…
Share table updated successfully.
Adding additional owner index to the share table, this can take some time…
Share table updated successfully.
Adding additional initiator index to the share table, this can take some time…
Share table updated successfully.
Adding additional mtime index to the filecache table, this can take some time…
Filecache table updated successfully.

Leave a Reply

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注