My app can't connect to postgres database minutes after being deployed

Problem description

When I run the script and just deploy the system, it works perfectly;
however, after some minutes of downtime, the system can no longer connect to the database.
After entering the login, the screen stays blank.
To make the system return to work, I have to pause and resume the deployment…

The deployment log shows the following errors:
psycopg2.InterfaceError: cursor already closed

Expected behavior

The database connection stays stable

Actual behavior

The connection between database and the app stops after minutes of deployment

Steps to reproduce

Access the system url and try to enter

Browser

Chrome

OS

Windows, Android, IOS

Device if mobile

Android, IOS

Plan

Core

I forgot to say that the language i’m using is Python

You can always edit your posts by clicking the pencil icon on the bottom right of your post

1 Like

Your case can be a lot of things, so I’d suggest making a robust logging around database connections and queries.

The database connections might be timing out due to inactivity. I know for a fact that many cloud database providers close idle connections after a certain period.

There is always a chance that configurations of the database are causing the connections to drop, like limitations and timeout settings,

You can also implement a retry mechanism to re-establish a connection if the initial connection fails or is dropped.

I did a retry mechanism in every cursor call ! But I still can’t connect to the database after a few minutes…
The strange thing is that the PostgresSql Compute Usage is still growing…