My PostgreSQL close unexpectedly the connection

Posted March 10, 2019 17.2k views
Server OptimizationPostgreSQLUbuntu 18.04

Hello I’ve a PostgreSQL server which is presenting a problem that always says the server close the connection unexpectedly, how can I fix this? I am using flask
This is the error:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


To learn more about what is happening here, it may be important for you to review the logs for Postgres. You can read more information about logging and error reporting on Postgres here:


We have same problem as well in digital ocean, we are unable to solve this issue. did you find any solution for that?

I have absolutely the same error with psycopg2 and can not find any solution. I submitted a ticket to the support. I can successfully connect with any GUI client or psql and make a query but it fails from within the application.

If anybody solved this?