Cascade of errors starting with RuntimeException: File entry could not be inserted but could also not be selected with getId() in order to perform an update

Nextcloud version (eg, 20.0.5): 21.0.5
Operating system and version (eg, Ubuntu 20.04): Debian 10-Linux 4.19.0-10-amd64 x86_64
Apache or nginx version (eg, Apache 2.4.25): 2.4.38 (Debian)
PHP version (eg, 7.4): 7.4.13
Database: PostgreSQL 11.7 (Debian 11.7-0+deb10u1)

The issue you are facing:
I’m getting this error regularly, I see it today at 14:25, 02:25, and at the same times yesterday. I don’t think it is new since nothing changed, I just noted it is regular now.
I have a previous topic with error on some external folders, I don’t know if they are related.
image

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

Steps to replicate it:

  1. It just happens

I tried some things like reindexing, occ files scan all, occ files cleanup… i feel like its something deeper inside the db but have no idea what and how to fix it.

Also, maybe related, my search is not working great. I use it mainly to access external storage and nothing is found on the main search page (/index.php/apps/fulltextsearch/). Using the popup search on the top right corner it finds my external files, contacts etc…
Elasticsearch can find a query from command line…

The output of your Nextcloud log in Admin > Logging:

https://pastebin.com/iuwaKMqT

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

<?php
$CONFIG = array (
  'instanceid' => 'REDACTED',
  'passwordsalt' => 'REDACTED',
  'secret' => 'REDACTED',
  'trusted_domains' => 
  array (
    0 => 'REDACTED.REDACTEDl.com.br',
  ),
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
  'datadirectory' => '/nextcloud_data',
  'dbtype' => 'pgsql',
  'version' => '21.0.4.1',
  'overwrite.cli.url' => 'https://REDACTED.REDACTEDl.com.br',
  'dbname' => 'nextclouddb',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'REDACTED',
  'installed' => true,
  'mail_from_address' => 'REDACTED',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'REDACTED.REDACTEDo.com',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.REDACTED.REDACTEDo.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => 'REDACTED@REDACTED.REDACTEDo.com',
  'mail_smtppassword' => 'REDACTED',
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'default_locale' => 'pt_BR',
  'default_phone_region' => 'BR',
);

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

[Fri Oct 15 00:00:01.893803 2021] [mpm_event:notice] [pid 629:tid 139819587785856] AH00489: Apache/2.4.38 (Debian) OpenSSL/1.1.1g configured -- resuming normal operations
[Fri Oct 15 00:00:01.893826 2021] [core:notice] [pid 629:tid 139819587785856] AH00094: Command line: '/usr/sbin/apache2'
[Fri Oct 15 00:16:50.435367 2021] [access_compat:error] [pid 809:tid 139819120301824] [client 209.141.62.185:54146] AH01797: client denied by server configuration: /var/www/html/nextcloud/config/getuser
[Fri Oct 15 02:32:36.882049 2021] [negotiation:error] [pid 810:tid 139819145479936] [client 45.146.164.110:55100] AH00687: Negotiation: discovered file(s) matching request: /var/www/html/nextcloud/console (None could be negotiated).
[Fri Oct 15 02:32:37.647411 2021] [core:error] [pid 809:tid 139818080130816] [client 45.146.164.110:48922] AH00126: Invalid URI in request POST /cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh HTTP/1.1
[Fri Oct 15 02:57:37.994265 2021] [authz_core:error] [pid 810:tid 139818231133952] [client 5.8.10.202:17052] AH01630: client denied by server configuration: /var/www/html/nextcloud/server-status
[Fri Oct 15 03:14:45.483656 2021] [core:error] [pid 810:tid 139819162265344] [client 172.105.189.111:44220] AH00126: Invalid URI in request HEAD /icons/.%2e/%2e%2e/apache2/icons/sphere1.png HTTP/1.1
[Fri Oct 15 08:01:14.739693 2021] [access_compat:error] [pid 810:tid 139819137087232] [client 209.141.56.212:51034] AH01797: client denied by server configuration: /var/www/html/nextcloud/config/getuser
[Fri Oct 15 09:10:10.041693 2021] [core:error] [pid 810:tid 139819257702144] [client 45.146.164.110:48060] AH00126: Invalid URI in request POST /cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh HTTP/1.1
[Fri Oct 15 11:17:10.468515 2021] [access_compat:error] [pid 809:tid 139818063345408] [client 209.141.56.212:50700] AH01797: client denied by server configuration: /var/www/html/nextcloud/config/getuser
[Fri Oct 15 13:01:10.606983 2021] [access_compat:error] [pid 810:tid 139818868651776] [client 209.141.62.185:59174] AH01797: client denied by server configuration: /var/www/html/nextcloud/config/getuser