Some indices are missing in the database. Connection error


Nextcloud version:
Operating system and version: Ubuntu 17.04
Apache: 2.4.18
PHP version: 7.2.12

The issue you are facing:

The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running “occ db:add-missing-indices” those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.

  • Missing index “share_with_index” in table “oc_share”.
  • Missing index “parent_index” in table “oc_share”.
  • Missing index “fs_mtime” in table “oc_filecache”.
    I tried running the command below to fix the above issue:

sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices

But i got the following error:

#56 {main}PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Configura in /var/www/nextcloud/lib/private/DB/Connection.php on line 64

Can someone Help me plz :frowning:

Still not working !..

Hey Etiennehb,

please could you provide us with the database software you are using and is the rest of NC working fine?

Thanks in advance

Everything is working fine ! (except having the error in my settings)
I am using mysql.

I saw that the version 8 could cause some problems but i don’t know how to fix this :frowning:

Can you please run sudo -u www-data php -i from your command line and check whether mysql and pdo_mysql come up with the correct version for your MySQL?

Since PHP has different php.ini and loaded modules depending on the way you are calling PHP (e.g. running php from command line vs. running php within your webserver).

The error message is saying, that it is missing the correct driver to execute the occ command.

#56 {main}PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /var/www/nextcloud/lib/private/DB/Connection.php:64

hum not sure where i can find those information there is so much text returned by that command !

You can use grep to narrow down the information output.


sudo -u www-data php -i | grep mysql

This should shorten down the information to the mysql bit. When you got that, you could add it in here so we can have a better look at it.

1 Like

Thanks for your time but i found the solution !
sudo mysql
ALTER TABLE nextcloud.oc_share ADD INDEX share_with_index (share_with) USING BTREE;
ALTER TABLE nextcloud.oc_share ADD INDEX parent_index (parent) USING BTREE;
ALTER TABLE nextcloud.oc_filecache ADD INDEX fs_mtime (mtime) USING BTREE;


sometimes it was of great help to remove the groupfolders-app from app-directory. and then run the occ db:add-missing-indices again…

groupfolders v2.0.x is interfering in a bad way with that.

Adding some help for shared hosting solutions…

  1. login with the terminal on ssh on your shared hosting (if possible)
  2. cd to your nextcloud folder

my location is, yours will be different: webmaster@shell:/domains/$

use the php command in the terminal with the correct path and missing OCC in the Mysql database…

php /domains/ db:add-missing-indices
php /domains/ db:add-missing-primary-keys
php /domains/ db:convert-filecache-bigint

for all errors on missing OCC database tables, just copy the “occ db: …” part and create your own command (with correct path to Nextcloud) to solve the errors in the Nextcloud settings.

replace the path to your nextcloud directory (mine is running in the, every hosting has a different path)

What din’t work was: sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices (i have no root on shared hosting)