[GH-ISSUE #5935] Unable to configure a db connection pool #29706

Closed
opened 2026-04-25 04:08:22 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @nowheresly on GitHub (Oct 6, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/5935

Bug Report

Installation Method

I want to use the app with postgresql and a connection pool. Following the documentation, it is stated to use the peewee connection url syntax described here

The peewee documentation states to use the following scheme postgres+pool to leverage a connection pool.

Yet, when we use this scheme, we get the following traceback on startup:

open-webui  | Traceback (most recent call last):
open-webui  |   File "/usr/local/bin/uvicorn", line 8, in <module>
open-webui  |     sys.exit(main())
open-webui  |              ^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
open-webui  |     return self.main(*args, **kwargs)
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
open-webui  |     rv = self.invoke(ctx)
open-webui  |          ^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
open-webui  |     return ctx.invoke(self.callback, **ctx.params)
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
open-webui  |     return __callback(*args, **kwargs)
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/main.py", line 410, in main
open-webui  |     run(
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/main.py", line 577, in run
open-webui  |     server.run()
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 65, in run
open-webui  |     return asyncio.run(self.serve(sockets=sockets))
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
open-webui  |     return runner.run(main)
open-webui  |            ^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
open-webui  |     return self._loop.run_until_complete(task)
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 69, in serve
open-webui  |     await self._serve(sockets)
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 76, in _serve
open-webui  |     config.load()
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/config.py", line 434, in load
open-webui  |     self.loaded_app = import_from_string(self.app)
open-webui  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/importer.py", line 19, in import_from_string
open-webui  |     module = importlib.import_module(module_str)
open-webui  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
open-webui  |     return _bootstrap._gcd_import(name[level:], package, level)
open-webui  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
open-webui  |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
open-webui  |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
open-webui  |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
open-webui  |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
open-webui  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
open-webui  |   File "/app/backend/open_webui/main.py", line 20, in <module>
open-webui  |     from open_webui.apps.audio.main import app as audio_app
open-webui  |   File "/app/backend/open_webui/apps/audio/main.py", line 10, in <module>
open-webui  |     from open_webui.config import (
open-webui  |   File "/app/backend/open_webui/config.py", line 13, in <module>
open-webui  |     from open_webui.apps.webui.internal.db import Base, get_db
open-webui  |   File "/app/backend/open_webui/apps/webui/internal/db.py", line 74, in <module>
open-webui  |     engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_pre_ping=True)
open-webui  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
open-webui  |   File "<string>", line 2, in create_engine
open-webui  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
open-webui  |     return fn(*args, **kwargs)  # type: ignore[no-any-return]
open-webui  |            ^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 550, in create_engine
open-webui  |     entrypoint = u._get_entrypoint()
open-webui  |                  ^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/url.py", line 758, in _get_entrypoint
open-webui  |     cls = registry.load(name)
open-webui  |           ^^^^^^^^^^^^^^^^^^^
open-webui  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 375, in load
open-webui  |     raise exc.NoSuchModuleError(
open-webui  | sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres.pool
open-webui exited with code 0

Looking at the traceback, we see that the app is using SqlAlchemy in addition to peewee, but is reusing the same connection url for both frameworks. Yet the url conventions used by SQLAlchemy does not follow the conventions used by peewee. See here for SQLAlchemy

Environment

  • **Open WebUI Version: v0.3.30

Expected Behavior:

It should be possible to use a connection pool as stated in the official documentation

Actual Behavior:

Any attempt to configure a connection pool fail

Reproduction Details

Steps to Reproduce:

Here is a simple docker-compose file that we can use to reproduce the issue:

services:
  ollama:
    volumes:
      - ollama:/root/.ollama
    container_name: ollama
    pull_policy: always
    tty: true
    restart: unless-stopped
    image: ollama/ollama:0.3.12

  open-webui:
    image: ghcr.io/open-webui/open-webui:v0.3.30
    container_name: open-webui
    volumes:
      - open-webui:/app/backend/data
    depends_on:
      - ollama
    ports:
      - 8080:8080
    environment:
      - 'OLLAMA_BASE_URL=http://ollama:11434'
      - 'WEBUI_SECRET_KEY='
#      - 'DATABASE_URL=postgresql://admin:password@postgres:5432/db'
      - 'DATABASE_URL=postgres+pool://admin:password@postgres:5432/db'
      - 'ADMIN_EMAIL=user@demo.lu'
    extra_hosts:
      - host.docker.internal:host-gateway
    restart: unless-stopped

  postgres:
    image: postgres:17
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
      POSTGRES_DB: db
    ports:
      - 5432:5432
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  ollama: {}
  open-webui: {}
  postgres: {}
Originally created by @nowheresly on GitHub (Oct 6, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/5935 # Bug Report ## Installation Method I want to use the app with postgresql and a connection pool. Following the documentation, it is stated to use the peewee connection url syntax described [here](https://docs.peewee-orm.com/en/latest/peewee/playhouse.html#connect) The peewee documentation states to use the following scheme `postgres+pool` to leverage a connection pool. Yet, when we use this scheme, we get the following traceback on startup: ``` open-webui | Traceback (most recent call last): open-webui | File "/usr/local/bin/uvicorn", line 8, in <module> open-webui | sys.exit(main()) open-webui | ^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__ open-webui | return self.main(*args, **kwargs) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main open-webui | rv = self.invoke(ctx) open-webui | ^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke open-webui | return ctx.invoke(self.callback, **ctx.params) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke open-webui | return __callback(*args, **kwargs) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/main.py", line 410, in main open-webui | run( open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/main.py", line 577, in run open-webui | server.run() open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 65, in run open-webui | return asyncio.run(self.serve(sockets=sockets)) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run open-webui | return runner.run(main) open-webui | ^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run open-webui | return self._loop.run_until_complete(task) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 69, in serve open-webui | await self._serve(sockets) open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/server.py", line 76, in _serve open-webui | config.load() open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/config.py", line 434, in load open-webui | self.loaded_app = import_from_string(self.app) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/uvicorn/importer.py", line 19, in import_from_string open-webui | module = importlib.import_module(module_str) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module open-webui | return _bootstrap._gcd_import(name[level:], package, level) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "<frozen importlib._bootstrap>", line 1204, in _gcd_import open-webui | File "<frozen importlib._bootstrap>", line 1176, in _find_and_load open-webui | File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked open-webui | File "<frozen importlib._bootstrap>", line 690, in _load_unlocked open-webui | File "<frozen importlib._bootstrap_external>", line 940, in exec_module open-webui | File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed open-webui | File "/app/backend/open_webui/main.py", line 20, in <module> open-webui | from open_webui.apps.audio.main import app as audio_app open-webui | File "/app/backend/open_webui/apps/audio/main.py", line 10, in <module> open-webui | from open_webui.config import ( open-webui | File "/app/backend/open_webui/config.py", line 13, in <module> open-webui | from open_webui.apps.webui.internal.db import Base, get_db open-webui | File "/app/backend/open_webui/apps/webui/internal/db.py", line 74, in <module> open-webui | engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_pre_ping=True) open-webui | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ open-webui | File "<string>", line 2, in create_engine open-webui | File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned open-webui | return fn(*args, **kwargs) # type: ignore[no-any-return] open-webui | ^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 550, in create_engine open-webui | entrypoint = u._get_entrypoint() open-webui | ^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/url.py", line 758, in _get_entrypoint open-webui | cls = registry.load(name) open-webui | ^^^^^^^^^^^^^^^^^^^ open-webui | File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 375, in load open-webui | raise exc.NoSuchModuleError( open-webui | sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres.pool open-webui exited with code 0 ``` Looking at the traceback, we see that the app is using SqlAlchemy in addition to peewee, but is reusing the same connection url for both frameworks. Yet the url conventions used by SQLAlchemy does not follow the conventions used by peewee. See [here for SQLAlchemy](https://docs.sqlalchemy.org/en/20/core/pooling.html) ## Environment - **Open WebUI Version: v0.3.30 ## Expected Behavior: It should be possible to use a connection pool as [stated in the official documentation](https://docs.openwebui.com/getting-started/env-configuration#database_url) ## Actual Behavior: Any attempt to configure a connection pool fail ## Reproduction Details **Steps to Reproduce:** Here is a simple docker-compose file that we can use to reproduce the issue: ``` services: ollama: volumes: - ollama:/root/.ollama container_name: ollama pull_policy: always tty: true restart: unless-stopped image: ollama/ollama:0.3.12 open-webui: image: ghcr.io/open-webui/open-webui:v0.3.30 container_name: open-webui volumes: - open-webui:/app/backend/data depends_on: - ollama ports: - 8080:8080 environment: - 'OLLAMA_BASE_URL=http://ollama:11434' - 'WEBUI_SECRET_KEY=' # - 'DATABASE_URL=postgresql://admin:password@postgres:5432/db' - 'DATABASE_URL=postgres+pool://admin:password@postgres:5432/db' - 'ADMIN_EMAIL=user@demo.lu' extra_hosts: - host.docker.internal:host-gateway restart: unless-stopped postgres: image: postgres:17 environment: POSTGRES_USER: admin POSTGRES_PASSWORD: password POSTGRES_DB: db ports: - 5432:5432 volumes: - postgres:/var/lib/postgresql/data volumes: ollama: {} open-webui: {} postgres: {} ```
Author
Owner

@nowheresly commented on GitHub (Oct 6, 2024):

Ok after reading this:

https://github.com/open-webui/open-webui/pull/3327

I understand that peewee is no more used and that the documentation is now obsolete.
I guess there's no way right now to configure a connection pool with a specific size

<!-- gh-comment-id:2395461150 --> @nowheresly commented on GitHub (Oct 6, 2024): Ok after reading this: https://github.com/open-webui/open-webui/pull/3327 I understand that peewee is no more used and that the documentation is now obsolete. I guess there's no way right now to configure a connection pool with a specific size
Author
Owner

@nowheresly commented on GitHub (Oct 6, 2024):

I made a pull request to enable pool configuration

<!-- gh-comment-id:2395477561 --> @nowheresly commented on GitHub (Oct 6, 2024): I made a pull request to enable pool configuration
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#29706