My PostgreSQL close unexpectedly the connection

March 10, 2019 3.3k views
Server Optimization PostgreSQL Ubuntu 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.

3 Answers

Greetings!

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:

https://www.postgresql.org/docs/9.1/runtime-config-logging.html

Jarland

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

  • Hi, did you solved an issue?

    • We don’t face with any issue yet, what we did change the version of psycopg2 to psycopg2==2.7.4. this issue was occurring rarely. We are still testing with this version as well so far everything is ok.

      • Thank you for the response! It turned out that I did not include my cluster in trusted hosts in DO db settings.

        P.S. I’m using psycopg2==2.8.5 and set poolpreping to True (when were trying to solve an issue) and it works fine, at least for now.

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?

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!