File entry could not be inserted but could also not be selected with getId() Scanner.php

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 (eg, 20.0.5): 22.2.3
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Nginx 1.18
PHP version (eg, 7.4): 8.0.13
Db : psql 13.5

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): n (Same error on 21.X.X)

Steps to replicate it:

  1. sudo -u USER1 php /var/www/nextcloud/occ files:scan USER
  2. Full scan ok
  3. Always same Error at end of scan

The output of your Nextcloud log in Admin > Logging:

RuntimeException: File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.

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

<?php
$CONFIG = array (
  'instanceid' => '************',
  'passwordsalt' => '*********',
  'secret' => '*****************',
  'default_phone_region' => 'FR',
  'trusted_domains' => 
  array (
    0 => 'MYWEBSERVER',
    1 => 'MYWEBSERVER.local',
  ),
  'datadirectory' => 'SOMEWHERE',
  'dbtype' => 'pgsql',
  'version' => '22.2.3.0',
  'overwrite.cli.url' => 'https://MYWEBSERVER',
  'dbname' => 'NameDb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'UserDb',
  'dbpassword' => 'PassDb',
  'installed' => true,
  'filelocking.enabled' => 'true',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => '0',
  ),
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'app_install_overwrite' => 
  array (
    0 => 'previewgenerator',
  ),
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'filesystem_check_changes' => 0,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 1,
  'log_type' => 'file',
  'logfile' => '/var/log/nextcloud/nextcloud.log',
  'logtimezone' => 'Europe/Paris',
  'log_rotate_size' => '104857600'
);

The output of your Apache/nginx/system log in /var/log/____:

{"reqId":"YkmKaFQJhcwlNWtJAOWc","level":3,"time":"2021-12-06T09:10:02+01:00","remoteAddr":"","user":"--","app":"files","method":"","url":"--","message":"File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.","userAgent":"--","version":"22.2.3.0","exception":{"Exception":"RuntimeException","Message":"File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/Files/Cache/Wrapper/CacheWrapper.php","line":135,"function":"insert","class":"OC\\Files\\Cache\\Cache","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":294,"function":"insert","class":"OC\\Files\\Cache\\Wrapper\\CacheWrapper","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":224,"function":"addToCache","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":427,"function":"scanFile","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":388,"function":"handleChildren","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":340,"function":"scanChildren","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":510,"function":"scan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Cache/Scanner.php","line":521,"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":509,"function":"runBackgroundScanJob","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/lib/private/Files/Utils/Scanner.php","line":185,"function":"backgroundScan","class":"OC\\Files\\Cache\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":89,"function":"backgroundScan","class":"OC\\Files\\Utils\\Scanner","type":"->"},{"file":"/var/www/nextcloud/apps/files/lib/BackgroundJob/ScanFiles.php","line":125,"function":"runScanner","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/Job.php","line":51,"function":"run","class":"OCA\\Files\\BackgroundJob\\ScanFiles","type":"->"},{"file":"/var/www/nextcloud/lib/private/BackgroundJob/TimedJob.php","line":58,"function":"execute","class":"OC\\BackgroundJob\\Job","type":"->"},{"file":"/var/www/nextcloud/cron.php","line":127,"function":"execute","class":"OC\\BackgroundJob\\TimedJob","type":"->"}],"File":"/var/www/nextcloud/lib/private/Files/Cache/Cache.php","Line":340,"CustomMessage":"--"},"id":"61add307359bd"}

error

2021-12-07 09:10:02.564 CET [39333] XXXXXX@YYYYYY ERREUR:  la valeur d'une clé dupliquée rompt la contrainte unique « fs_storage_path_hash »
2021-12-07 09:10:02.564 CET [39333] XXXXXX@YYYYYY DÉTAIL:  La clé « (storage, path_hash)=(3, 13c337fec*************1cf86af2c) » existe déjà.
2021-12-07 09:10:02.564 CET [39333] XXXXXX@YYYYYY INSTRUCTION :  INSERT INTO "oc_filecache" ("mimepart", "mimetype", "mtime", "size", "etag", "storage_mtime", "permissions", "name", "parent", "checksum", "path_hash", "path", "storage") VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)

WHAT CAN I DO ???

I have see the same error here : File name too long error and timeout during cron job · Issue #22836 · nextcloud/server · GitHub

or here : Error moving / renaming folders NC 12.0.0 (stable) · Issue #5448 · nextcloud/server · GitHub
(Integrity constraint violation: Duplicate entry)

or here : Postgres "duplicate key value" after 18.0.1 upgrade · Issue #19494 · nextcloud/server · GitHub

or here : UniqueConstraintViolationException overview ticket · Issue #12369 · nextcloud/server · GitHub

But no answer at all. Can I have help please ?