mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #23382] [CLOSED] fix: improve PostgreSQL database sided reliability for migrations #50222
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23382
Author: @Classic298
Created: 4/3/2026
Status: ❌ Closed
Base:
dev← Head:migration📝 Commits (5)
7769b16fix1aaf286fix: address code review feedback on migration116a6b8rebased05ef5c5fix: reduce BATCH_SIZE to avoid PG bind param limit, commit per indexd93fe55fix: guard non-dict JSON, incremental flushing, offline txn parity📊 Changes
2 files changed (+349 additions, -90 deletions)
View changed files
📝
backend/open_webui/migrations/env.py(+6 -1)📝
backend/open_webui/migrations/versions/8452d01d26d7_add_chat_message_table.py(+343 -89)📄 Description
The
8452d01d26d7("Add chat_message table") migration fails on large PostgreSQL datasets (50+ GB) due to three interacting database-side issues that the existing Python-side batching fix (#21542) does not address:Unbounded transaction:
env.pywraps all migrations in a singlecontext.begin_transaction(). Thebegin_nested()savepoints in_flush_batch()nest inside this outer transaction — nothing actually commits to disk until the entire migration returns. For large datasets this generates massive WAL that can't be recycled, causing managed PostgreSQL services (AlloyDB, Cloud SQL, RDS) to kill the connection.Indexes + FK created before backfill: The migration creates 7 secondary indexes and a FK constraint before inserting any data. Every INSERT must update all 7 B-tree indexes + validate the FK — ~9 WAL records per row. PostgreSQL's own bulk loading docs explicitly warn against this pattern.
Server-side cursor invalidated by COMMIT:
stream_results=Truecreates aWITHOUT HOLDcursor on PostgreSQL. You can't naively "add commits inside the loop" — the cursor dies on the first COMMIT. A different pagination strategy is required.Related issues
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.