Strategies to handle database cooldown

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. 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

  1. Implement data read/write with retry
  2. Use pool connections
  3. 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

Good point!

Just want to add one point here. 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 node-postgres