Moved from another thread
^ describes that databases will cooldown after 1 minute if there are no connections to it. If a cooldown happens, that’s a good thing – it’s not in use and that’s what lets us offer serverless pricing. The best thing to do is simply to reconnect as you need to. Most popular Postgres programming libraries have connection pools that auto reconnect.
bit.io has open source libraries to make it easy for you:
Since this is a serverless Postgres which keeps cooling down or sleep after 60 seconds, connections interruption is unavoidable. The best approach are
- Implement data read/write with retry
- Use pool connections
- This is important. You need to inform the client SDK of the idleConnectionTimeout in advance to somewhere around 50 seconds so that it can prepare itself and work accordingly
Just want to add one point here. bit.io does not terminate connections every 60s. It terminates connections that are inactive or idle in a transaction after 5 minutes.
Otherwise, connections always terminate after 60 minutes. Importantly, the database will only cool down if there are 0 connections for 60s. That said, network interruptions, load balancing, failover, etc all can close connections and so as @versitastorevrpreprd says, retries and pooling will make your client robust to disconnection. An always-available, long-lived connection is a dangerous assumption for production environment, even if it isn’t to serverless Postgres.
The most effective solution is the last one
idleConnectionTimeout, I eliminated connection errors with that plus your network tweaks
What language and package are you using?
The config is
idleTimeoutMillis: 50 * 1000 in nodejs