[GH-ISSUE #24234] issue: Windows PostgreSQL startup fails with psycopg ProactorEventLoop error #58901

Open
opened 2026-05-06 00:23:23 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ppoak on GitHub (Apr 29, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/24234

Bug Report

Check Existing Issues

  • I have searched the existing issues and discussions.

I found an older related Windows event loop discussion for aiodns / WindowsSelectorEventLoopPolicy (#10813), but I did not find a matching report for the current Open WebUI v0.9.x PostgreSQL runtime path using psycopg v3 async connections.

Installation Method

Pip Install / uvx

Open WebUI Version

v0.9.2

Ollama Version (if applicable)

Not applicable.

Operating System

Windows 11 Pro for Workstations, 64-bit

  • Version: 10.0.26200
  • Build: 26200

Browser (if applicable)

Not applicable. The backend fails during application startup before the web UI is available.

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of Open WebUI available from open-webui@latest at the time of testing.
  • I have checked the browser console logs. Not applicable because startup fails before the browser can connect.
  • I have checked the Docker container logs. Not applicable because this is a pip/uvx install, not Docker.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

Open WebUI should start successfully on Windows when configured with a PostgreSQL DATABASE_URL.

At minimum, the Windows startup path should use an event loop compatible with psycopg v3 async connections, or Open WebUI should document/handle the required Windows selector event loop configuration when PostgreSQL is used.

Actual Behavior

Open WebUI v0.9.2 fails during FastAPI lifespan startup when DATABASE_URL points to PostgreSQL.

The sync migration path succeeds, but the runtime async SQLAlchemy engine uses postgresql+psycopg://.... On Windows, uvicorn 0.41.0 creates a ProactorEventLoop for the server process, and psycopg v3 async connections reject that loop:

psycopg.InterfaceError: Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'

Adding --with psycopg2 does not avoid the failure because Open WebUI converts PostgreSQL runtime URLs to postgresql+psycopg://... in open_webui/internal/db.py, so runtime async DB access still uses psycopg v3.

Steps to Reproduce

  1. On Windows 11, configure Open WebUI with a PostgreSQL database:

    DATABASE_URL=postgresql://<user>:<password>@localhost:5432/<database>
    
  2. Start Open WebUI through uvx with Python 3.11:

    uvx --python 3.11 --env-file C:/Users/<user>/.env --with psycopg2 open-webui@latest serve
    
  3. Wait for startup to reach application lifespan initialization.

  4. Observe that startup exits with Application startup failed and the psycopg ProactorEventLoop error.

Logs & Screenshots

Environment details from the failing setup:

open-webui 0.9.2
uvicorn 0.41.0
psycopg 3.2.9
sqlalchemy 2.0.48
Python 3.11.9
uvx 0.10.9
Windows 11 Pro for Workstations 10.0.26200, 64-bit

Relevant startup log:

v0.9.2 - building the best AI user interface.

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO:     Started server process [...]
INFO:     Waiting for application startup.

Traceback (most recent call last):
  File ".../sqlalchemy/engine/base.py", line 143, in __init__
    self._dbapi_connection = engine.raw_connection()
  ...
  File ".../sqlalchemy/dialects/postgresql/psycopg.py", line 812, in connect
    await_only(creator_fn(*arg, **kw))
  File ".../sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
    value = await result
  File ".../psycopg/connection_async.py", line 104, in connect
    raise e.InterfaceError(
psycopg.InterfaceError: Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'

sqlalchemy.exc.InterfaceError: (psycopg.InterfaceError) Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'
(Background on this error at: https://sqlalche.me/e/20/rvf5)

Application startup failed. Exiting.

I also confirmed that PostgreSQL itself is reachable on localhost:5432; the failure is not a connection refused/authentication problem.

Additional Information

I tested a local workaround by monkey-patching uvicorn's asyncio loop factory before importing Open WebUI:

import asyncio
import uvicorn.loops.asyncio as uvicorn_asyncio

uvicorn_asyncio.asyncio_loop_factory = lambda use_subprocess=False: asyncio.SelectorEventLoop

from open_webui import serve

serve()

Starting Open WebUI through this wrapper succeeds, and GET http://127.0.0.1:8080/health returns:

200 {"status":true}

This suggests the immediate issue is that the Open WebUI + uvicorn startup path on Windows uses ProactorEventLoop, while the v0.9.x PostgreSQL async runtime path now requires a selector-compatible loop for psycopg v3.

Possible fixes could include one of the following:

  • Ensure Open WebUI's Windows startup path uses a selector event loop when PostgreSQL/psycopg async runtime DB access is configured.
  • Pass/configure a uvicorn loop factory compatible with psycopg on Windows.
  • Document an official Windows + PostgreSQL startup workaround for pip/uvx installs.
Originally created by @ppoak on GitHub (Apr 29, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/24234 # Bug Report ## Check Existing Issues - [x] I have searched the existing issues and discussions. I found an older related Windows event loop discussion for `aiodns` / `WindowsSelectorEventLoopPolicy` (#10813), but I did not find a matching report for the current Open WebUI v0.9.x PostgreSQL runtime path using psycopg v3 async connections. ## Installation Method Pip Install / uvx ## Open WebUI Version v0.9.2 ## Ollama Version (if applicable) Not applicable. ## Operating System Windows 11 Pro for Workstations, 64-bit - Version: 10.0.26200 - Build: 26200 ## Browser (if applicable) Not applicable. The backend fails during application startup before the web UI is available. ## Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of Open WebUI available from `open-webui@latest` at the time of testing. - [x] I have checked the browser console logs. Not applicable because startup fails before the browser can connect. - [x] I have checked the Docker container logs. Not applicable because this is a pip/uvx install, not Docker. - [x] I have listed steps to reproduce the bug in detail. ## Expected Behavior Open WebUI should start successfully on Windows when configured with a PostgreSQL `DATABASE_URL`. At minimum, the Windows startup path should use an event loop compatible with `psycopg` v3 async connections, or Open WebUI should document/handle the required Windows selector event loop configuration when PostgreSQL is used. ## Actual Behavior Open WebUI v0.9.2 fails during FastAPI lifespan startup when `DATABASE_URL` points to PostgreSQL. The sync migration path succeeds, but the runtime async SQLAlchemy engine uses `postgresql+psycopg://...`. On Windows, uvicorn 0.41.0 creates a `ProactorEventLoop` for the server process, and psycopg v3 async connections reject that loop: ```text psycopg.InterfaceError: Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())' ``` Adding `--with psycopg2` does not avoid the failure because Open WebUI converts PostgreSQL runtime URLs to `postgresql+psycopg://...` in `open_webui/internal/db.py`, so runtime async DB access still uses psycopg v3. ## Steps to Reproduce 1. On Windows 11, configure Open WebUI with a PostgreSQL database: ```env DATABASE_URL=postgresql://<user>:<password>@localhost:5432/<database> ``` 2. Start Open WebUI through uvx with Python 3.11: ```powershell uvx --python 3.11 --env-file C:/Users/<user>/.env --with psycopg2 open-webui@latest serve ``` 3. Wait for startup to reach application lifespan initialization. 4. Observe that startup exits with `Application startup failed` and the psycopg `ProactorEventLoop` error. ## Logs & Screenshots Environment details from the failing setup: ```text open-webui 0.9.2 uvicorn 0.41.0 psycopg 3.2.9 sqlalchemy 2.0.48 Python 3.11.9 uvx 0.10.9 Windows 11 Pro for Workstations 10.0.26200, 64-bit ``` Relevant startup log: ```text v0.9.2 - building the best AI user interface. INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO: Started server process [...] INFO: Waiting for application startup. Traceback (most recent call last): File ".../sqlalchemy/engine/base.py", line 143, in __init__ self._dbapi_connection = engine.raw_connection() ... File ".../sqlalchemy/dialects/postgresql/psycopg.py", line 812, in connect await_only(creator_fn(*arg, **kw)) File ".../sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn value = await result File ".../psycopg/connection_async.py", line 104, in connect raise e.InterfaceError( psycopg.InterfaceError: Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())' sqlalchemy.exc.InterfaceError: (psycopg.InterfaceError) Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())' (Background on this error at: https://sqlalche.me/e/20/rvf5) Application startup failed. Exiting. ``` I also confirmed that PostgreSQL itself is reachable on `localhost:5432`; the failure is not a connection refused/authentication problem. ## Additional Information I tested a local workaround by monkey-patching uvicorn's asyncio loop factory before importing Open WebUI: ```python import asyncio import uvicorn.loops.asyncio as uvicorn_asyncio uvicorn_asyncio.asyncio_loop_factory = lambda use_subprocess=False: asyncio.SelectorEventLoop from open_webui import serve serve() ``` Starting Open WebUI through this wrapper succeeds, and `GET http://127.0.0.1:8080/health` returns: ```text 200 {"status":true} ``` This suggests the immediate issue is that the Open WebUI + uvicorn startup path on Windows uses `ProactorEventLoop`, while the v0.9.x PostgreSQL async runtime path now requires a selector-compatible loop for psycopg v3. Possible fixes could include one of the following: - Ensure Open WebUI's Windows startup path uses a selector event loop when PostgreSQL/psycopg async runtime DB access is configured. - Pass/configure a uvicorn loop factory compatible with psycopg on Windows. - Document an official Windows + PostgreSQL startup workaround for pip/uvx installs.
Author
Owner

@rgaricano commented on GitHub (Apr 29, 2026):

it's reported, workaround: https://github.com/open-webui/open-webui/issues/24152#issuecomment-4336307770

<!-- gh-comment-id:4342944013 --> @rgaricano commented on GitHub (Apr 29, 2026): it's reported, workaround: https://github.com/open-webui/open-webui/issues/24152#issuecomment-4336307770
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#58901