High-availability: ActiveRecord::ConnectionNotEstablished during database restart

For security updates (mainly for Linux kernel updates) we need to restart the database server (e.g. weekly). It’s a PostgreSQL installation with about 200M records on Ubuntu.

The problem is that during the database restart there are always some application errors:

Some like this:

ActiveRecord::ConnectionNotEstablished: could not connect to server: Connection refused

And other similar, like this:

PG::Error: could not connect to server: Connection refused

Is this normal? Or there are better ways to handle this short downtime (a few seconds) during db restart?

I expected ActiveRecord to retry the connection for some seconds

I have found that the MySQL adapter seems to support a reconnect: true flag in database.yml. This can prevent errors in case of a database reboot for example.

This feature was added a long time ago for MySQL:

Does anyone know if there’s an equivalent for PostgreSQL?

Related: