Reduce RDS (Postgresql) downtime for frequent software releases ?

Hello,

our developers deploy new software a few times a month. Usually each new release requires DB changes. Of course we need to take a backup before (in addition to normal schedule). Our old approach was to take the DB down and run full backup. The new idea is to:

  1. shutdown RDS DB
  2. take RDS snapshot
  3. start the RDS DB

And now the questions:

- is there any other solution to reduce the downtime ?

- do we have to wait until step 2 has finished before carrying out step 3 ?

UPDATE: This is highly regulated business sector.

you’re rebuilding the entire db from scratch when you make a change?

RDS snapshots are point-in-time, you shouldn’t require more than a short write suspension and you definitely don’t need to shut down the instance.

What are steps 1 and 3 for?

Why can’t you make a backup before the deployment? It doesn’t need to be offline. Does it often go wrong that you have to restore the db and have missing data?

Granted I don’t know Postgres well, but since online backups are a feature of any modern RDBMS, I assume PG does them too.

An RDS snapshot should be sufficient here. In addition your definition of done should require that every DB change either has a rollback script OR is always backwards compatible. So, for example, no deleting of tables or renaming of columns.

Why would you need a full backup? Are you not testing your changes before applying them to production? We intentionally don’t make forward breaking database changes so rollbacks don’t also require a migration rollback and migrations are never destructive.

don’t shut down, just take the snapshot and roll in your new changes

Are there any docs that says we don’t need to shutdown to have a consistent, working backup ?

No, we do not.

Any manuals that says we don’t need to shutdown to have a consistent, working backup ?

Check out point-in-time restores. At least for RDS PostgreSQL and I believe MySQL you should be able to restore your database to a specific time by the second. It works by restoring the latest automated snapshot and then replaying transaction logs that is uploaded to S3 behind the scenes.

would you be so kind as to explain why you need to shut it down a few times a month?

Snapshots have existed in RDS for a very long time. The ability to stop an RDS database is more recent. Regardless of if there’s some doc that explicitly states it, it’s common-knowledge that snapshots in RDS do not require you to stop/start your DB. Think about the ‘automatic’ backups that RDS does daily – have you been thinking RDS was stopping/starting your instance every day to do those?

The consistency will depend on whether you are using transactions for writes. Postgres is ACID compliant, and snapshots should include any journaling associated with it.

If you do a bunch of writes without a coordinated transaction in your app, then you could have some issues.

There is a bit of a fallacy that you can somehow avoid losing a write if you take a backup right after you do a write. While this is true, the reality is that you should be prepared to lose all writes for whatever interval you have on your backups. In other words, what would happen if the snapshot happened right before a write to the database? You need to know the maximum number of minutes or hours of data you can tolerate losing, not the minimum amount.

And you should also know that depending on how writes are configured, a write might be written to a journal, but not fully flushed to disk.

Now, in practice, with N replicas, the likelihood of failure of all nodes before data is flushed is pretty near zero..

Lastly, you can restore snapshots to external/temp instances to periodically test them.

You probably do not need to take the database offline if you are using proper transactions.

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html

Amazon RDS creates a storage volume snapshot of your DB instance, backing up the entire DB instance and not just individual databases. Creating this DB snapshot on a Single-AZ DB instance results in a brief I/O suspension that can last from a few seconds to a few minutes, depending on the size and class of your DB instance

Have you read https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html ? It explains how snapshots work

No manual is going to list all the possible things that might exist but not matter; it would be infinitely long. If it were a requirement it would list it.

Fix your software and stop making extremely breaking changes; next step would be releasing multiple times per day. Or just call it deployments. Unless you’re in a highly regulated business sector none of the nineties development practices are beneficial anymore.

Don’t just read docs - test it. Create a snapshot while your server is running and restore. You will find that it will create a new DB instance and you can log in and verify it

Seriously if you’re doing backups and not testing restores - you’re not focusing enough on the important part.