Connection issue with neon DB and FastAPI application deployed on Vercel
FastAPI application that is connected to Neon DB (serverless Postgres) works locally, but fails to establish a database connection on deployment in Vercel.
lifespan
or startup event handlers for initializing the database pool seem to not execute or fail in the deployed environment. No proper error statement is shown. What is the source of this issue? . Is it Vercel or NeonDB?
What are the alternatives to keep DB connection alive throughout session. I want the DB pool connection to be closed only when FastAPI app stops running.
Here is the code snippet
I have tried following alternative as well. (It didn't work.)
Currently I am opening and closing pool connection for each and every function (FastAPI endpoint) which seems inefficient. Please suggest a solution for this issue.0 Replies