Repository navigation
[Bug]: Nextcloud keeps idle database connection for each preview generation enqueued for imaginary #65820
Description
⚠️ This issue respects the following points: ⚠️
- This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug (if unsure, ask the Community Help Forum).
- This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
- I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Supported major versions and current patch levels).
- I agree to follow Nextcloud's Code of Conduct.
- I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description
When nextcloud has the generation of a lot of previews with imaginary enqueued, it keeps an idle connection to the database open for each enqueued image. As preview generation jobs can take some time, this can easily overwhelm the max_connections limit of postgresql.
The amount of open idle database connections is neither limited by the preview_concurrency_new nor preview_concurrency_all option.
I haven’t checked if the problem also applies to other preview generators.
Steps to reproduce
- Setup nextcloud to use postgres with a reasonable connection limit i. e. 100 and preview generation through imaginary.
- Run
php occ preview:cleanup. - Open a directory with a huge amount of images (≫100) and quickly scroll around in it.
- The log will be full of „Failed to connect to the database“ errors.
Even better is to use socat tcp-listen:9000,fork 'exec:sleep inf!!open:/dev/null' as a dummy imaginary that just takes forever to reply. In that case, the amount of open database connections can easily be perceived with netstat -n | grep 5432.
Expected behavior
There shouldn’t be an unbounded amount (the amount of enqueued image previews) of database connections open idling for an indefinite amount of time (the amount it takes to generate all enqueued image previews).
Either the connections should be bounded (e. g. to preview_concurrency_new) or they should be shortlived.
Nextcloud Server version
34
Operating system
Debian/Ubuntu
PHP engine version
PHP 8.5
Web server
Apache (supported)
Database engine version
PostgreSQL
Is this bug present after an update or on a fresh install?
Fresh Nextcloud Server install
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
{
"system": {
"htaccess.RewriteBase": "\/",
"memcache.local": "\\OC\\Memcache\\APCu",
"apps_paths": [
{
"path": "\/var\/www\/html\/apps",
"url": "\/apps",
"writable": false
},
{
"path": "\/var\/www\/html\/custom_apps",
"url": "\/custom_apps",
"writable": true
}
],
"memcache.distributed": "\\OC\\Memcache\\Redis",
"memcache.locking": "\\OC\\Memcache\\Redis",
"redis": {
"host": "***REMOVED SENSITIVE VALUE***",
"password": "***REMOVED SENSITIVE VALUE***",
"port": 0
},
"upgrade.disable-web": true,
"instanceid": "***REMOVED SENSITIVE VALUE***",
"passwordsalt": "***REMOVED SENSITIVE VALUE***",
"secret": "***REMOVED SENSITIVE VALUE***",
"trusted_domains": [
"localhost"
],
"datadirectory": "***REMOVED SENSITIVE VALUE***",
"dbtype": "pgsql",
"version": "34.0.5.1",
"dbname": "***REMOVED SENSITIVE VALUE***",
"dbhost": "***REMOVED SENSITIVE VALUE***",
"dbtableprefix": "oc_",
"dbuser": "***REMOVED SENSITIVE VALUE***",
"dbpassword": "***REMOVED SENSITIVE VALUE***",
"installed": true,
"maintenance": false,
"preview_max_x": 2048,
"preview_max_y": 2048,
"jpeg_quality": 60,
"preview_format": "webp",
"enabledPreviewProviders": {
"0": "OC\\Preview\\Imaginary",
"1": "OC\\Preview\\Image",
"2": "OC\\Preview\\MarkDown",
"3": "OC\\Preview\\MP3",
"4": "OC\\Preview\\TXT",
"5": "OC\\Preview\\OpenDocument",
"6": "OC\\Preview\\Movie",
"7": "OC\\Preview\\Krita",
"9": "OC\\Preview\\MKV",
"10": "OC\\Preview\\AVI",
"11": "OC\\Preview\\MP4",
"13": "OC\\Preview\\ImaginaryPDF",
"14": "OCA\\Eurooffice\\Preview"
},
"enable_previews": true,
"trashbin_retention_obligation": "auto, 30",
"versions_retention_obligation": "auto, 30",
"activity_expire_days": 30,
"maintenance_window_start": 100,
"auth.bruteforce.protection.enabled": true,
"ratelimit.protection.enabled": true,
"trusted_proxies": "***REMOVED SENSITIVE VALUE***",
"preview_imaginary_url": "***REMOVED SENSITIVE VALUE***",
"default_phone_region": "DE",
"serverid": 445,
"app_install_overwrite": [],
"data-fingerprint": "103b5af42cc2305eff756c8ce67a6c09"
}
}List of activated Apps
Enabled:
- activity: 7.0.0
- admin_audit: 1.24.0
- appstore: 1.0.0
- bruteforcesettings: 7.0.0
- calendar: 6.6.3
- circles: 34.0.0
- cloud_federation_api: 1.18.0
- comments: 1.24.0
- contacts: 8.9.2
- contactsinteraction: 1.15.0
- cospend: 4.3.0
- dashboard: 7.14.0
- dav: 1.40.0
- federatedfilesharing: 1.24.0
- federation: 1.24.0
- files: 2.6.0
- files_downloadlimit: 5.2.0
- files_external: 1.26.0
- files_lock: 34.0.1
- files_pdfviewer: 7.0.0
- files_reminders: 1.7.0
- files_sharing: 1.26.0
- files_trashbin: 1.24.0
- files_versions: 1.27.0
- firstrunwizard: 7.0.0-dev.0
- forms: 5.4.1
- logreader: 7.0.0
- lookup_server_connector: 1.22.0
- nextcloud_announcements: 6.0.0
- notifications: 7.0.0-dev.1
- oauth2: 1.22.0
- office: 1.0.0
- password_policy: 6.0.0-dev.0
- photos: 7.0.0
- polls: 9.3.0
- privacy: 6.0.0-dev.1
- profile: 1.3.0
- provisioning_api: 1.24.0
- recommendations: 7.0.0
- related_resources: 5.0.0-dev.0
- serverinfo: 6.0.0
- settings: 1.17.0
- sharebymail: 1.24.0
- support: 6.0.0
- survey_client: 6.0.0-dev.0
- suspicious_login: 12.0.0-dev.0
- systemtags: 1.24.0
- tasks: 0.18.1
- text: 8.0.0
- theming: 2.9.0
- twofactor_backupcodes: 1.23.0
- twofactor_nextcloud_notification: 8.0.0
- twofactor_totp: 16.0.0
- updatenotification: 1.24.0
- user_status: 1.14.0
- viewer: 7.0.0-dev.0
- weather_status: 1.14.0
- webhook_listeners: 1.6.0
- workflowengine: 2.16.0
Disabled:
- app_api: 34.0.0 (installed 5.0.2)
- encryption: 2.22.0
- spreed: 24.0.6 (installed 24.0.6)
- user_ldap: 1.25.0Nextcloud Signing status
No errors have been found.Nextcloud Logs
{"reqId":"4gm4v8xSHKHhUMLRggEU","level":3,"time":"2026-10-23T18:48:00+00:00","remoteAddr":"2001:7c7:2128:600:629a:22e6:b4e9:7ca1","user":"admin","app":"index","method":"GET","url":"/core/preview?fileId=215122&x=128&y=128&mimeFallback=true&v=343048&a=0","scriptName":"/index.php","message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:158.0) Gecko/20100101 Firefox/158.0","version":"34.0.5.1","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute","Code":7,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":458,"function":"connect","class":"OC\\DB\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":416,"function":"getDatabasePlatformVersion","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/3rdparty/doctrine/dbal/src/Connection.php","line":323,"function":"detectDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":946,"function":"getDatabasePlatform","class":"Doctrine\\DBAL\\Connection","type":"->","args":[]},{"file":"/var/www/html/lib/private/DB/ConnectionAdapter.php","line":277,"function":"getDatabaseProvider","class":"OC\\DB\\Connection","type":"->","args":[false]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":85,"function":"getDatabaseProvider","class":"OC\\DB\\ConnectionAdapter","type":"->","args":[]},{"file":"/var/www/html/lib/private/User/Database.php","line":397,"function":"expr","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/lib/private/User/Database.php","line":466,"function":"loadUser","class":"OC\\User\\Database","type":"->","args":["admin"]},{"file":"/var/www/html/lib/private/User/Manager.php","line":154,"function":"userExists","class":"OC\\User\\Database","type":"->","args":["admin"]},{"file":"/var/www/html/lib/private/User/Session.php","line":187,"function":"get","class":"OC\\User\\Manager","type":"->","args":["admin"]},{"file":"/var/www/html/lib/private/User/Session.php","line":229,"function":"getUser","class":"OC\\User\\Session","type":"->","args":[]},{"file":"/var/www/html/lib/base.php","line":1127,"function":"isLoggedIn","class":"OC\\User\\Session","type":"->","args":[]},{"file":"/var/www/html/index.php","line":25,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":235,"message":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute","CustomMessage":"Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] connection to server on socket \"/run/postgresql/.s.PGSQL.5432\" failed: FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute"},"id":"6adbc5dc1a013"}Additional info
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity