Occ files:scan error | oc_file_locks_id_seq reached maximum value

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:

S

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 (19.0.0):
Operating system and version (Ubuntu 20.04):
Apache or nginx version (Apache 2.4.41):
PHP version (7.4.3):

The issue you are facing:

Hello, i am currently running a nextcloud 19.0.0. Every Minute i run a cronjob which looks like this:

sudo -u www-data php /var/www/nextcloud/occ files:scan --all

I do this because i place the files directly into the filesystem via smb, without this cronjob the system wont load the files into the webapp. This worked great until now. I get the error listed below. i guess it is because the Oc_file_locks_id_seq is on its max value. But how can i resolve this state and prevent it from happening again?

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

Steps to replicate it:

i guess if in database table “oc_file_locks_id_seq” the coloumn “last_value” first(and only) row value is at 2147483647

The output of your Nextcloud log in Admin > Logging:

{"reqId":"lrBccFrVHbUygjJxe9OB","level":3,"time":"2020-07-20T16:25:01+02:00","remoteAddr":"","user":"--","app":"files","method":"","url":"--","message":{"Exception":"Doctrine\\DBAL\\Exception\\DriverException","Message":"An exception occurred while executing 'INSERT INTO \"oc_file_locks\" (\"key\", \"lock\", \"ttl\") VALUES(?, ?, ?) ON CONFLICT DO NOTHING' with params [\"files\\/bf5863ceee4506d3842781c80ef70d40\", -1, 1595258701]:\n\nSQLSTATE[2200H]: <<Unknown error>>: 7 ERROR:  nextval: reached maximum value of sequence \"oc_file_locks_id_seq\" (2147483647)","Code":0,"Trace":[{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php","line":169,"function":"convertException","class":"Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver","type":"->"},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php","line":145,"function":"wrapException","class":"Doctrine\\DBAL\\DBALException","type":"::"},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1063,"function":"driverExceptionDuringQuery","class":"Doctrine\\DBAL\\DBALException","type":"::"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":214,"function":"executeUpdate","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/AdapterPgSql.php","line":60,"function":"executeUpdate","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":259,"function":"insertIgnoreConflict","class":"OC\\DB\\AdapterPgSql","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":141,"function":"insertIgnoreConflict","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":202,"function":"initLockField","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Common.php","line":750,"function":"acquireLock","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":594,"function":"acquireLock","class":"OC\\Files\\Storage\\Common","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":333,"function":"acquireLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":506,"function":"scan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":517,"function":"OC\\Files\\Cache\\{closure}","class":"OC\\Files\\Cache\\Scanner","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":505,"function":"runBackgroundScanJob","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Utils/Scanner.php","line":186,"function":"backgroundScan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":83,"function":"backgroundScan","class":"OC\\Files\\Utils\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":111,"function":"runScanner","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/Job.php","line":62,"function":"run","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/TimedJob.php","line":57,"function":"execute","class":"OC\\BackgroundJob\\Job","type":"->"},{"file":"/var/www/nextcloud/cron.php","line":126,"function":"execute","class":"OC\\BackgroundJob\\TimedJob","type":"->"}],"File":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php","Line":79,"Previous":{"Exception":"Doctrine\\DBAL\\Driver\\PDOException","Message":"SQLSTATE[2200H]: <<Unknown error>>: 7 ERROR:  nextval: reached maximum value of sequence \"oc_file_locks_id_seq\" (2147483647)","Code":"2200H","Trace":[{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1054,"function":"execute","class":"Doctrine\\DBAL\\Driver\\PDOStatement","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":214,"function":"executeUpdate","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/AdapterPgSql.php","line":60,"function":"executeUpdate","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":259,"function":"insertIgnoreConflict","class":"OC\\DB\\AdapterPgSql","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":141,"function":"insertIgnoreConflict","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":202,"function":"initLockField","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Common.php","line":750,"function":"acquireLock","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":594,"function":"acquireLock","class":"OC\\Files\\Storage\\Common","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":333,"function":"acquireLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":506,"function":"scan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":517,"function":"OC\\Files\\Cache\\{closure}","class":"OC\\Files\\Cache\\Scanner","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":505,"function":"runBackgroundScanJob","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Utils/Scanner.php","line":186,"function":"backgroundScan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":83,"function":"backgroundScan","class":"OC\\Files\\Utils\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":111,"function":"runScanner","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/Job.php","line":62,"function":"run","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/TimedJob.php","line":57,"function":"execute","class":"OC\\BackgroundJob\\Job","type":"->"},{"file":"/var/www/nextcloud/cron.php","line":126,"function":"execute","class":"OC\\BackgroundJob\\TimedJob","type":"->"}],"File":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php","Line":119,"Previous":{"Exception":"PDOException","Message":"SQLSTATE[2200H]: <<Unknown error>>: 7 ERROR:  nextval: reached maximum value of sequence \"oc_file_locks_id_seq\" (2147483647)","Code":"2200H","Trace":[{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php","line":117,"function":"execute","class":"PDOStatement","type":"->"},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1054,"function":"execute","class":"Doctrine\\DBAL\\Driver\\PDOStatement","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":214,"function":"executeUpdate","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/AdapterPgSql.php","line":60,"function":"executeUpdate","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":259,"function":"insertIgnoreConflict","class":"OC\\DB\\AdapterPgSql","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":141,"function":"insertIgnoreConflict","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/Lock/DBLockingProvider.php","line":202,"function":"initLockField","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Common.php","line":750,"function":"acquireLock","class":"OC\\Lock\\DBLockingProvider","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":594,"function":"acquireLock","class":"OC\\Files\\Storage\\Common","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":333,"function":"acquireLock","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":506,"function":"scan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":517,"function":"OC\\Files\\Cache\\{closure}","class":"OC\\Files\\Cache\\Scanner","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":505,"function":"runBackgroundScanJob","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Utils/Scanner.php","line":186,"function":"backgroundScan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":83,"function":"backgroundScan","class":"OC\\Files\\Utils\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":111,"function":"runScanner","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/Job.php","line":62,"function":"run","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/TimedJob.php","line":57,"function":"execute","class":"OC\\BackgroundJob\\Job","type":"->"},{"file":"/var/www/nextcloud/cron.php","line":126,"function":"execute","class":"OC\\BackgroundJob\\TimedJob","type":"->"}],"File":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php","Line":117}},"CustomMessage":"--"},"userAgent":"--","version":"19.0.0.12","id":"5f15abcdd6827"}

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

<?php
$CONFIG = array (
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '192.168.5.2',
    2 => '.de',
    3 => '',
  ),
  'datadirectory' => '/mnt/ncdata/NextCloud',
  'dbtype' => 'pgsql',
  'version' => '19.0.0.12',
  'overwrite.cli.url' => 'https://.de/',
  'dbname' => 'nextcloud_db',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'ncadmin',
  'dbpassword' => '=q',
  'installed' => true,
  'instanceid' => '',
  'upgrade.disable-web' => 'true',
  'log_type' => 'file',
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'loglevel' => '2',
  'log.condition' =>
  array (
    'apps' =>
    array (
      0 => 'admin_audit',
    ),
  ),
  'mail_smtpmode' => 'smtp',
  'remember_login_cookie_lifetime' => '1800',
  'log_rotate_size' => '10485760',
  'trashbin_retention_obligation' => 'auto, 180',
  'versions_retention_obligation' => 'auto, 365',
  'simpleSignUpLink.shown' => 'false',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'filelocking.enabled' => true,
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' =>
  array (
    'host' => '/var/run/redis/redis-server.sock',
    'port' => 0,
    'timeout' => 0.5,
    'dbindex' => 0,
    'password' => 'e[..]Rk',
  ),
  'logtimezone' => 'Europe/Berlin',
  'htaccess.RewriteBase' => '/',
  'maintenance' => false,
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'vio',
  'mail_domain' => '.de',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.office365.com',
  'mail_smtpport' => '25',
  'mail_smtpname' => '',
  'mail_smtppassword' => '',
  'default_language' => 'de',
  'force_locale' => 'de',
);

Sorry no real idea for reset “oc_file_locks_id_seq”.
You can remove the locked entrys in MariaDB. But i think it do not decrease the counter :wink:

But perhaps you can after solving your problem change the setting for file locking.

‘filelocking.enabled’ => true,
This is enabled by default.

Prevents concurrent processes from accessing the same files at the same time. Can help prevent side effects that would be caused by concurrent operations. Mainly relevant for very large installations with many users working with shared files.

https://docs.nextcloud.com/server/19/admin_manual/configuration_server/config_sample_php_parameters.html

Perhaps you also can use or not use Redis.

https://docs.nextcloud.com/server/15/admin_manual/configuration_server/caching_configuration.html