Unable to purge Deleted Files

Nextcloud version (eg, 20.0.5): 21.0.1
Operating system and version (eg, Ubuntu 20.04): DSM 6.2.3-25426
Apache or nginx version (eg, Apache 2.4.25): unknown
PHP version (eg, 7.4): 7.4.19

The issue you are facing:
For one user account there are GBs of files in files_trashbin, although on the web UI under Deleted Files no files are shown. So I tried sudo -u www-data php occ trashbin:cleanup username and received:
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 438272 bytes) in /var/www/html/3rdparty/composer/autoload_real.php on line 37

I set PHP_MEMORY_LIMIT=6G and gave 8GB to the container. The same error persists.

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

Steps to replicate it:

  1. sudo -u www-data php occ trashbin:cleanup username

The output of your Nextcloud log in Admin > Logging:

Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) at /var/www/html/apps/files_trashbin/lib/Helper.php#86

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

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'overwriteprotocol' => 'https',
  'trusted_proxies' => 
  array (
    0 => '127.0.0.1',
    1 => '<redacted>',
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => '<redacted>',
  'mail_smtpport' => '465',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpauth' => true,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpname' => '<redacted>',
  'mail_smtppassword' => '<redacted>a',
  'mail_from_address' => '<redacted>',
  'mail_domain' => '<redacted>t',
  'instanceid' => '<redacted>',
  'passwordsalt' => '<redacted>',
  'secret' => '<redacted>',
  'trusted_domains' => 
  array (
    <redacted>
  ),
  'datadirectory' => '/userdata',
  'dbtype' => 'pgsql',
  'version' => '21.0.1.1',
  'overwrite.cli.url' => 'https://redacted:8443',
  'dbname' => 'postgres',
  'dbhost' => 'postgres-latest',
  'dbport' => '<redacted>',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'postgres',
  'dbpassword' => '<redacted>',
  'installed' => true,
  'mail_smtpstreamoptions' => 
  array (
    'ssl' => 
    array (
      'allow_self_signed' => true,
      'verify_peer' => false,
      'verify_peer_name' => true,
    ),
  ),
  'loglevel' => 2,
  'maintenance' => false,
  'updater.secret' => '<redacted>',
);

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

[Sun Apr 03 12:40:43.244373 2022] [php7:error] [pid 36] [client 172.18.0.1:59480] PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/apps/files_trashbin/lib/Helper.php on line 86

This error did not occur in the Apache log after I raised the PHP mem limit.

I do know hat 21.0.1 is not supported and tried to update to 21.0.9, which is basically not feasible as Synology DSM handles docker. So I tried to update the container to “latest” (i.e. 23.xx), but it wouldn’t work.

So my current problem is to get rid of the deleted files.
After that I will probably need help to export all user data in a way that it can be imported in a fresh 23.x install. (helps and pointer welcome).

Can you check nextcloud.log in /var/www/ or as admin in right hand side menu for errors. Paste them here or in a pastebin.

I searched your php error on the forum and found:

And, Here are results for searching that general error

I did send the errors, they were all the same.
I did search for them in the forum - of course - on my own, before posting, and none of the answers helped.
I do not have APCu activated, so that post does not apply.

Any further help and suggestions are welcome.

What now worked for me was setting the env var right in the sudo command:

sudo -u www-data PHP_MEMORY_LIMIT=6G php occ trashbin:cleanup --all-users