BerriAI/litellm · error · HTTPException
Postgres DB Not connected
Error message
Postgres DB Not connected
What it means
Returned by POST /customer/block (alias /end_user/block) when the proxy's prisma_client is None, i.e. the process started without a database connection. Blocking end users requires upserting blocked=true rows in LiteLLM_EndUserTable, so without Prisma the endpoint aborts with HTTP 500 'Postgres DB Not connected'.
Source
Thrown at litellm/proxy/management_endpoints/customer_endpoints.py:180
```
"""
from litellm.proxy.proxy_server import prisma_client
try:
records: Final = []
if prisma_client is not None:
for id in data.user_ids:
record = await _typed_table(EndUserRepository(prisma_client)).upsert(
where={"user_id": id},
data={
"create": {"user_id": id, "blocked": True},
"update": {"blocked": True},
},
)
records.append(record)
await _evict_end_user_cache_keys(_end_user_cache_keys(data.user_ids))
else:
raise HTTPException(
status_code=500,
detail={"error": "Postgres DB Not connected"},
)
return {"blocked_users": records}
except Exception as e:
verbose_proxy_logger.error("An error occurred - %s", e)
raise HTTPException(status_code=500, detail={"error": str(e)})
@router.post(
"/end_user/unblock",
tags=["Customer Management"],
dependencies=[Depends(user_api_key_auth)],
include_in_schema=False,
)
@router.post(
"/customer/unblock",View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set DATABASE_URL to a PostgreSQL connection string (postgresql://user:pass@host:5432/db) in the proxy environment and restart
- Check proxy startup logs for Prisma connect errors and fix credentials/network/SSL issues
- Confirm the DB is live via another DB-backed route (e.g. GET /key/info or GET /customer/list) before retrying the block
- If you do not need persistence, stop calling block endpoints - they have no in-memory mode
Example fix
# before litellm --config config.yaml # config.yaml has no database_url -> /customer/block 500s # after export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/litellm litellm --config config.yaml
Defensive patterns
Strategy: validation
Validate before calling
import os
def proxy_has_database() -> bool:
url = os.getenv("DATABASE_URL", "")
return url.startswith(("postgresql://", "postgres://"))
assert proxy_has_database(), "proxy needs DATABASE_URL before /customer/block can work" Try / catch
try:
resp = client.post("/customer/block", json={"user_ids": ids})
except HTTPException as e:
if e.status_code == 500 and "Not connected" in str(e.detail):
raise RuntimeError("proxy has no DATABASE_URL configured") from e
raise Prevention
- Always configure DATABASE_URL when deploying the proxy with management endpoints
- Monitor startup logs for Prisma connection failures instead of discovering them via 500s on first API call
- Remember LiteLLM management endpoints are Postgres-only - sqlite/mysql URLs will not satisfy them
When it happens
Trigger: POST /customer/block (or /end_user/block) with {"user_ids": [...]} against a proxy started without DATABASE_URL, or whose Prisma connection failed at startup leaving prisma_client None.
Common situations: Running litellm via pip with a config.yaml that has no database_url; DATABASE_URL pointing at a non-Postgres engine (management endpoints need postgresql://); the DB was unreachable at boot so every DB-backed management route 500s.
Related errors
- DB not connected. This endpoint needs a database; set DATABA
- Not connected to DB!
- Database not connected. Connect a database to your proxy - h
- Failed updating customer data. User ID does not exist passed
- Database not connected. Connect a database to your proxy - h
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/abb055a01d136153.
Report an issue: GitHub.