Forums

Multiple call to postgres db stop responding

Hi PythonAnywhere,

ISSUE: When calling multiple times to postgres db from python code. The DB server stops responding and won't receive any data. I had earlier faced this issue in mysql DB as well. I have a python bottle application deployed in PythonAnywhere and if I get multiple hits to the application the DB won't responds and the api received no data.

CURRENT WORKAROUND: Once I reload the application again from WEB tab. It works perfectly fine again. This seems not feasible.

Can you please solve this issue ASAP or suggest.

Regards, Sanjib

That really sounds like you have some issue with how you're accessing the database. I'm guessing you're opening a connection when your web app starts and then, when it times out or something goes wrong with the connection, you have no way of recovering the connection, so it stalls.

Hi, thanks for replying. In my case, i open and close the connection for each transactions. E.g,

For transaction 1

conn_open() transaction_1 execution conn_close()

For transaction 2

conn_open() transaction_2 execution conn_close()

Even if there is any error. I am closing the connection in CATCH block.

Please suggest.

One more note: I am using SqlALchemy. In a single connection, I am doing multiple calls to db (is this an issue causing in here) for e.g., conn_open() 1st call to DB 2nd call to DB 3nd call to DB 4nd call to DB conn_close()

Note: In local environment it worked fine.

I face the same issue in MySQL connection in PythonAnywhere. If the DB call is more than 3 time in the same single connection it throws an error.

Please suggest.

See our help page about using SQLAlchemy with MySQL here: http://help.pythonanywhere.com/pages/UsingSQLAlchemywithMySQL/. The same thing should apply for Postgres.

Thanks Glenn. Trying this. Hope it solves the issue I am facing .