SQLAlchemy - Postgres Connection Issue

954 views
Skip to first unread message

Shankar Ganesh

unread,
Oct 15, 2018, 10:01:07 AM10/15/18
to sqlalchemy
Hi

Flask with SQLAlchemy 

Flask==0.10.1

SQLAlchemy==1.0.8


In production after a lot of usages (connection) we are getting this error. After that restarting the server helps, what will be the permanent solution

OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly\\n\\tThis probably means the server terminated abnormally\\n\\tbefore or while processing the request.\

Any ideas on that?



Thanks,
Shankar

Shankar Ganesh

unread,
Oct 15, 2018, 10:46:36 AM10/15/18
to sqlalchemy
More information

Similarly, we are creating a scoped session, we are doing session.close()

I tried Null Pool which doesn't help

Any ideas on that?

Relevant finding Is it odd that my SQLAlchemy MySQL connection always ends up sleeping?


Handle mysql restart in SQLAlchemy

Jonathan Vanasco

unread,
Oct 15, 2018, 11:13:45 AM10/15/18
to sqlalchemy
There are a few strategies to handling disconnects that are outlined in the docs:

https://docs.sqlalchemy.org/en/latest/core/pooling.html#dealing-with-disconnects


Shankar Ganesh

unread,
Oct 15, 2018, 1:13:00 PM10/15/18
to sqlalchemy
@jonathan 

I went through that. What is the possible reason for disconnect ? I am not restarting my dbs.

Jonathan Vanasco

unread,
Oct 15, 2018, 1:21:20 PM10/15/18
to sqlalchemy
your database logs may indicate why it is closing the connection or what underlying error happened.

there are dozens, if not hundreds, of potential reasons why an error like this may be happening.  this could be from anything, including having too many connections, to an issue on your database app, or even an issue on your server or connectivity, etc.  
Reply all
Reply to author
Forward
0 new messages