#30003·open-webui

issue: Unindexed get_pending_files_for_knowledge query causes full table scans / database saturation

Author: dgarciaf18Created Sep 14, 2026Updated Sep 30, 2026
Labelsbugconfirmed issue

Before Submitting

  • I searched open and closed issues and discussions for an existing report.
  • I checked whether this is already fixed on the dev branch or latest source.
  • I understand that maintainers want a well-written issue before any code pull request.
  • I am using the latest available version of Open WebUI for my install method.
  • This is not a security vulnerability.

Installation Method

Docker

Open WebUI Version

v0.11.1

Operating System

Windows 11

Browser

No response

Ollama Version

No response

Summary

The GET /api/v1/knowledge/{id}/files/pending endpoint (added in v0.9.6) is backed by Files.get_pending_files_for_knowledge in backend/open_webui/models/files.py, which runs this query:

sql
SELECT file.id, file.user_id, file.hash, file.filename, file.path, file.data, file.meta, file.created_at, file.updated_at
FROM file
WHERE CAST(((file.meta -> $1::TEXT) ->> $2::TEXT) AS VARCHAR) = $3::VARCHAR
  AND CAST((file.data ->> $4::TEXT) AS VARCHAR) IN ($5::VARCHAR, $6::VARCHAR)
  AND (file.id NOT IN (SELECT knowledge_file.file_id FROM knowledge_file WHERE knowledge_file.knowledge_id = $7::VARCHAR))
ORDER BY file.created_at DESC

All predicates filter on JSONB fields (meta->'data'->>'knowledge_id' and data->>'status') with no supporting index. Because file.data stores full extracted document content (multi-MB per row, stored as TOAST), every call performs an expensive sequential scan that detoasts every row in the table.

The endpoint is polled aggressively:

  • Frontend: setInterval(..., 5000) with no overlap guard in the KnowledgeBase.svelte component. Polls every 5s on any Knowledge Base workspace page
  • Backend: SSE event_stream() in routers/knowledge.py re-runs the query every 3s while an upload is in progress Under concurrent users, these polls stack into many parallel sequential scans, saturating the database.

This very same issue was also submitted at https://github.com/open-webui/open-webui/issues/25717 , self-closed.

Expected Behavior

Opening a Knowledge Base page or polling for in-flight files should complete in milliseconds, with cost proportional to the number of pending files, not total table size.

Actual Behavior

Every call performs a full sequential scan of the file table. On deployments with even moderately sized file tables, each scan takes minutes. Multiple concurrent polls (multiple users, multiple tabs, 5s intervals) pile up and saturate the database.

Steps to Reproduce

  1. Deploy Open WebUI v0.9.6+ backed by PostgreSQL
  2. Populate the file table with a non-trivial number of rows where file.data contains extracted document content
  3. Open a Knowledge Base in Workspace → Knowledge
  4. Observe PostgreSQL pg_stat_activity. The pending-files query runs as a sequential scan on file
  5. Open multiple tabs or have multiple users on Knowledge pages. See how the scans stack and DB CPU/IO saturates

Logs, Screenshots, and Config

SELECT count(*) FROM file WHERE data->>'status' IN ('pending','processing'); took ~1m43s on a deployment with ~58k rows (4.4GB table).

pg_stat_activity at peak: 34+ concurrent executions of the same query, all active for minutes, all sequential scans of the file table.

Load by waits (AAS): 105.43

Additional Information

Manual fix/workaround:

sql
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_file_pending_knowledge
ON file ((meta -> 'data' ->> 'knowledge_id'))
WHERE (data ->> 'status') IN ('pending', 'processing');

A DB migrator creating this index was submitted as PR #25718 (self-closed without merge).