© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•13mo ago•
1 reply
Pranav Prakash

server closed the connection unexpectedly

We are using SQLAlchemy to connect to our supabase instance. We use transaction pooler for connecting. We have an XL instance & the "Connection pooling configuration -> Pool size" is set to 192. (80% of max). We have 2 apps (1 fastapi webserver & 1 celery worker) that performs rw ops on the instance. The num of calls from fastapi is less & the celery is doing most of the heavy rw operations. Our config for the SQLAlchemy engine uses a connection pool with following params:

celery:
pool size: 50
max overflow: 10
pool timeout: 60s
pool recycle: 1000
pool pre ping: True

fastapi:
pool size: 30
max overflow: 10 
pool timeout: 60s
pool recycle: 1000
pool pre ping: True
celery:
pool size: 50
max overflow: 10
pool timeout: 60s
pool recycle: 1000
pool pre ping: True

fastapi:
pool size: 30
max overflow: 10 
pool timeout: 60s
pool recycle: 1000
pool pre ping: True


We keep getting the following error

        "message": "Task failed: (psycopg2.OperationalError) server closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\nserver closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\n\n[SQL: ***redacted sql***]\n(Background on this error at: https://sqlalche.me/e/20/e3q8)",
        "message": "Task failed: (psycopg2.OperationalError) server closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\nserver closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.\n\n[SQL: ***redacted sql***]\n(Background on this error at: https://sqlalche.me/e/20/e3q8)",


The SQL query varies but this error is consistent. What can we do to ensure this doesn't happen?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

PrismaClientKnownRequestError: Server has closed the connection
SupabaseSSupabase / help-and-questions
3y ago
How to fix Error: P1017: Server has closed the connection. supabase
SupabaseSSupabase / help-and-questions
6mo ago
Cannot connect to database on port 5432 – P1001 error and psql connection closed unexpectedly
SupabaseSSupabase / help-and-questions
7mo ago
Connection to supavisor closed by server after 40 seconds
SupabaseSSupabase / help-and-questions
3y ago