{"record":{"id":"abb055a01d136153","repo":"BerriAI/litellm","slug":"postgres-db-not-connected","errorCode":null,"errorMessage":"Postgres DB Not connected","messagePattern":"Postgres DB Not connected","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/customer_endpoints.py","lineNumber":180,"sourceCode":"        ```\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    try:\n        records: Final = []\n        if prisma_client is not None:\n            for id in data.user_ids:\n                record = await _typed_table(EndUserRepository(prisma_client)).upsert(\n                    where={\"user_id\": id},\n                    data={\n                        \"create\": {\"user_id\": id, \"blocked\": True},\n                        \"update\": {\"blocked\": True},\n                    },\n                )\n                records.append(record)\n            await _evict_end_user_cache_keys(_end_user_cache_keys(data.user_ids))\n        else:\n            raise HTTPException(\n                status_code=500,\n                detail={\"error\": \"Postgres DB Not connected\"},\n            )\n\n        return {\"blocked_users\": records}\n    except Exception as e:\n        verbose_proxy_logger.error(\"An error occurred - %s\", e)\n        raise HTTPException(status_code=500, detail={\"error\": str(e)})\n\n\n@router.post(\n    \"/end_user/unblock\",\n    tags=[\"Customer Management\"],\n    dependencies=[Depends(user_api_key_auth)],\n    include_in_schema=False,\n)\n@router.post(\n    \"/customer/unblock\",","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/customer_endpoints.py#L162-L198","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nlitellm --config config.yaml   # config.yaml has no database_url -> /customer/block 500s\n\n# after\nexport DATABASE_URL=postgresql://postgres:postgres@localhost:5432/litellm\nlitellm --config config.yaml","handlingStrategy":"validation","validationCode":"import os\n\n\ndef proxy_has_database() -> bool:\n    url = os.getenv(\"DATABASE_URL\", \"\")\n    return url.startswith((\"postgresql://\", \"postgres://\"))\n\n\nassert proxy_has_database(), \"proxy needs DATABASE_URL before /customer/block can work\"","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.post(\"/customer/block\", json={\"user_ids\": ids})\nexcept HTTPException as e:\n    if e.status_code == 500 and \"Not connected\" in str(e.detail):\n        raise RuntimeError(\"proxy has no DATABASE_URL configured\") from e\n    raise","preventionTips":["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"],"tags":["litellm","postgres","prisma","database-connection","customer-management"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}