Skip to content

Open WebUI PostgreSQL Setup (2026): DATABASE_URL, Docker Compose and pgvector

8–12 minutes
Woman on a rooftop terrace holding a tablet with an OPEN WEBUI POSTGRESQL card, hook scale up with Postgres

Out of the box, Open WebUI keeps everything in a single SQLite file called webui.db. For one person on a local SSD, that is perfect.

Once you add a team, run more than one container, or put the data folder on network storage, SQLite starts to lock up, and PostgreSQL becomes the right home for your data.

Switching is one environment variable, DATABASE_URL. The part people miss is that changing it does not move your existing data. Open WebUI starts with an empty PostgreSQL database, so you want to make this choice early, or plan the move carefully.

This guide shows when you actually need PostgreSQL, a working Docker Compose setup, the connection URL format, pgvector for knowledge bases, connection pool sizing, what happens to existing SQLite data, backups and fixes for common errors. It follows the official Open WebUI documentation as of December 2026.

TL;DR

  • Set: DATABASE_URL=postgresql://user:password@db-host:5432/openwebui
  • Need it when: several replicas, Kubernetes or Swarm, or data on NFS or other network storage.
  • Do not need it: single user or small team on a local SSD. SQLite is fine.
  • No data migration: changing the URL starts an empty database. Decide before you have real data.
  • Vectors too: VECTOR_DB=pgvector stores knowledge base embeddings in PostgreSQL with the vector extension.
  • Passwords: URL-encode special characters, for example @ becomes %40.

Do You Need PostgreSQL?

The Open WebUI docs are clear that SQLite is a good choice for personal use, home labs and small single-instance setups, as long as the data folder sits on a locally attached SSD or NVMe drive. PostgreSQL becomes required, not optional, in these cases:

Your setup SQLite PostgreSQL
One user, local SSD Recommended Optional
Small team, one container, local SSD Fine Nice to have
Data folder on NFS, SMB, Azure Files, CephFS or a network PVC Not supported Required
More than one replica or container Not supported, risks corruption Required
Kubernetes or Docker Swarm Not supported Required
Many concurrent users, database is locked errors Struggles Recommended

SQLite on network storage fails under load because every commit waits for a slow network sync and SQLite file locking is unreliable over network filesystems.

The docs list the symptoms: QueuePool limit of size N overflow M reached, multi-minute stalls, WAL deadlocks and possible corruption. No tuning fixes that. Move to PostgreSQL or move webui.db to a local disk.

The DATABASE_URL Format

DATABASE_URL follows SQLAlchemy’s URL scheme. The default is sqlite:///${DATA_DIR}/webui.db. For PostgreSQL:

DATABASE_URL=postgresql://USER:PASSWORD@HOST:5432/DATABASE
  • Use a plain postgresql:// URL. Open WebUI picks its async driver (psycopg 3) on its own.
  • URL-encode special characters in the password. p@ssword becomes p%40ssword.
  • Do not leave DATABASE_URL empty. An empty value stops startup with Could not parse SQLAlchemy URL from given URL string. Unset it or give a full URL.

Or build it from separate variables

Instead of one URL you can set DATABASE_TYPE, DATABASE_HOST, DATABASE_PORT, DATABASE_NAME, DATABASE_USER and DATABASE_PASSWORD.

When type, host, port, name and at least one of user or password are all set, Open WebUI builds the URL from them and ignores DATABASE_URL, even if you set it. If any is missing, it falls back to DATABASE_URL or SQLite. Pick one style and stick with it.

Other useful variables include DATABASE_SCHEMA to use a specific PostgreSQL schema, and DATABASE_ENABLE_IAM_TOKEN_AUTH for AWS RDS IAM tokens instead of a static password.

Set Up Open WebUI With PostgreSQL in Docker Compose

This is the simplest way to run a fresh Open WebUI on PostgreSQL on one machine. It uses the pgvector/pgvector image, which is PostgreSQL with the vector extension already installed, so the same database can also hold knowledge base embeddings later.

  1. Create a folder such as open-webui-pg and a .env file in it with a strong password: POSTGRES_PASSWORD=change-me-long-random
  2. Create docker-compose.yml with the content below.
  3. Start it with docker compose up -d.
  4. Watch the logs with docker compose logs -f open-webui until the migrations finish and the server starts.
  5. Open http://localhost:3000 and create the first admin account. It is stored in PostgreSQL now.
services:
  db:
    image: pgvector/pgvector:pg17
    restart: unless-stopped
    environment:
      POSTGRES_USER: openwebui
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: openwebui
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U openwebui -d openwebui"]
      interval: 5s
      retries: 10

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "3000:8080"
    environment:
      DATABASE_URL: postgresql://openwebui:${POSTGRES_PASSWORD}@db:5432/openwebui
      WEBUI_SECRET_KEY: ${WEBUI_SECRET_KEY}
      OLLAMA_BASE_URL: http://host.docker.internal:11434
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - open-webui:/app/backend/data

volumes:
  pgdata:
  open-webui:

Add WEBUI_SECRET_KEY to the .env file too. A fixed secret key keeps sessions and stored API keys working across restarts and updates. The open-webui volume is still needed, because uploaded files and, unless you use pgvector, the vector store still live in the data folder.

Notice the host is db, the Compose service name, not localhost. Inside the Open WebUI container, localhost is the container itself. Our Open WebUI connection error guide explains this in detail, and the Open WebUI with Ollama guide covers the Ollama side.

Use an Existing PostgreSQL Server

If you already run PostgreSQL, create a database and a role that owns it:

CREATE ROLE openwebui WITH LOGIN PASSWORD 'change-me-long-random';
CREATE DATABASE openwebui OWNER openwebui;

Then point Open WebUI at it:

docker run -d -p 3000:8080 \
  -e DATABASE_URL="postgresql://openwebui:change-me-long-random@192.168.1.20:5432/openwebui" \
  -v open-webui:/app/backend/data \
  --name open-webui --restart always ghcr.io/open-webui/open-webui:main

The role needs permission to create and alter tables, because Open WebUI runs its own schema migrations at startup. Keep the database on an internal network, use strong unique credentials and allow only the Open WebUI host in pg_hba.conf.

pip installs

For a pip install, install the PostgreSQL extra. The docs show pip install "open-webui[postgres]" for this, and open-webui[all] also includes it. Then export DATABASE_URL before running open-webui serve.

Store Embeddings With pgvector

Knowledge bases and document chat store embeddings in a vector database. By default that is ChromaDB inside the data folder, which, like SQLite, is not suitable for multiple replicas. With PostgreSQL in place, pgvector is the natural choice:

VECTOR_DB=pgvector
# Optional: a different PostgreSQL for vectors. When unset, DATABASE_URL is used.
PGVECTOR_DB_URL=postgresql://openwebui:password@db:5432/openwebui
Variable Default What it does
PGVECTOR_DB_URL Value of DATABASE_URL Where vectors are stored
PGVECTOR_CREATE_EXTENSION true Runs CREATE EXTENSION vector. Set false if an admin already enabled it, so Open WebUI can run as a non-superuser
PGVECTOR_INITIALIZE_MAX_VECTOR_LENGTH 1536 Maximum embedding dimension
PGVECTOR_INDEX_METHOD unset (auto) ivfflat or hnsw

Switching the vector database does not move existing embeddings either. After switching, re-upload or re-index your knowledge base documents. For more on how retrieval works, see our Open WebUI RAG guide, and for embedding models, our Ollama embeddings guide.

Connection Pool Sizing

Each Open WebUI process keeps a pool of database connections. With DATABASE_POOL_SIZE unset, PostgreSQL uses SQLAlchemy’s default of 5 connections plus 10 overflow.

  • Once you set DATABASE_POOL_SIZE, the overflow default drops to 0, so set DATABASE_POOL_MAX_OVERFLOW too.
  • A good start for busy instances is DATABASE_POOL_SIZE=15 and DATABASE_POOL_MAX_OVERFLOW=20.
  • Each worker has a synchronous and an asynchronous pool. With pgvector, the vector store gets its own pool even on the same server.
  • Example from the docs: size 15 plus overflow 20, four replicas, one worker each gives up to 280 application connections (2 x 35 x 4). PostgreSQL’s default max_connections is 100, so raise it or shrink the pools.
DATABASE_POOL_SIZE=15
DATABASE_POOL_MAX_OVERFLOW=20
DATABASE_POOL_TIMEOUT=30
DATABASE_POOL_RECYCLE=3600

For multiple replicas, set ENABLE_DB_MIGRATIONS=false on every instance except one, so only one process runs schema migrations. Multi-replica setups also need Redis with REDIS_URL and WEBSOCKET_MANAGER=redis.

What About My Existing SQLite Data?

This is the big one. The official docs say plainly that changing the URL does not migrate data between databases. If you point an existing install at PostgreSQL, you get a fresh, empty instance: no users, no chats, no settings. Your webui.db is untouched, so you can switch back by removing DATABASE_URL.

Your realistic options:

  1. Start fresh on PostgreSQL. This is the cleanest path for a new team deployment.
  2. Move people’s chats by hand. Users can export their chats from settings on the old instance and import them on the new one. Recreate models, prompts and knowledge bases.
  3. Use a third-party migration tool at your own risk. These are not part of Open WebUI and need to match your exact Open WebUI version. Test on a copy first.

Whatever you choose, take a full backup of the data folder first, following our Open WebUI backup guide, and keep the same WEBUI_SECRET_KEY.

Back Up PostgreSQL

With PostgreSQL, copying the Open WebUI data folder no longer captures users and chats. Back up the database with PostgreSQL’s own tools:

# Back up
docker compose exec -T db pg_dump -U openwebui -Fc openwebui > openwebui-$(date +%Y%m%d).dump

# Restore into an empty database
docker compose exec -T db pg_restore -U openwebui -d openwebui --clean < openwebui-20261204.dump

Still back up the open-webui volume for uploaded files, and keep your secret key safe. Back up before every update, because updates run schema migrations. See how to update Open WebUI.

Troubleshooting

Could not parse SQLAlchemy URL from given URL string

DATABASE_URL is set but empty, or malformed. Unset it or give a full URL. Check for a leftover DATABASE_URL in your shell from another project.

connection refused or timeouts at startup

Open WebUI cannot reach the database. Use the Compose service name (db) or a LAN IP, not localhost. Make sure PostgreSQL listens on the network and pg_hba.conf allows the Open WebUI host. In Compose, add a healthcheck so Open WebUI waits for the database.

password authentication failed

Wrong credentials, or an unencoded special character in the password. Encode @, :, / and #. Note that the PostgreSQL image only reads POSTGRES_PASSWORD on first start, so changing it later in Compose does nothing to an existing volume.

Everything is empty after switching

Expected. No data was migrated. Remove DATABASE_URL to go back to SQLite, or follow the migration options.

permission denied to create extension "vector"

The role is not a superuser. Have an admin run CREATE EXTENSION vector; in the database, then set PGVECTOR_CREATE_EXTENSION=false.

too many connections

Pools across all replicas exceed max_connections. Lower DATABASE_POOL_SIZE and overflow, or raise max_connections.

My DATABASE_URL is ignored

The separate DATABASE_TYPE, DATABASE_HOST and related variables are set and win. Remove them or use them consistently.

FAQ

Does Open WebUI support PostgreSQL?

Yes. Set DATABASE_URL to a postgresql:// URL. SQLite and PostgreSQL are both supported, and MariaDB is available as a vector store option.

Should I use PostgreSQL for a home lab?

Usually not. SQLite on a local SSD is fine for personal and small single-instance setups.

Will switching to PostgreSQL move my chats?

No. Changing the URL starts an empty database. Your webui.db stays as it was.

Which PostgreSQL version should I use?

Use a current supported release. The pgvector/pgvector image tags such as pg17 give you PostgreSQL with pgvector included.

Do I still need the data volume with PostgreSQL?

Yes. Uploaded files, the cache and, without pgvector, the vector store still live in /app/backend/data.

Can I use a managed database like RDS or Supabase?

Yes, any reachable PostgreSQL works. On AWS RDS you can use IAM token auth with DATABASE_ENABLE_IAM_TOKEN_AUTH.

How many users can SQLite handle?

There is no fixed number. The limit is concurrent writes and storage speed. If you see database is locked or pool timeouts, move to PostgreSQL.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman on a rooftop terrace holding a tablet with an OPEN WEBUI POSTGRESQL card, hook scale up with Postgres