Postgres database migration "zero" downtime
how can I get close to zero downtime when having database migrations.


Set up a streaming replica pair, with a master and a replica. Use WAL archiving in addition to streaming replication to deal with connectivity drops. Make sure your application is easily reconfigured to switch to a different server for if you need to fail over; if it's not easy to reconfigure, run a local PgBouncer on each node so you can switch it to connect to a different PostgreSQL without needing to mess with the rest of the server config.

A tool like repmgr makes this considerably simpler.

To learn more, read the manual.