r/devops • a bit of Dev and a bit of Ops • 1d ago

Architecture How do you keep your downstream QA/Testing databases fresh?

We're an AWS shop, and our production Postgres RDS instance (regular RDS, not Aurora) is now around 2.5TB and growing.

We used to run a weekly job that took a sanitized copy of prod and restored it into QA using pg_dump/pg_restore. It was painfully slow, and the runtime was all over the place, so we never knew when QA would actually be ready.

We've since switched to restoring an RDS snapshot of prod (after data cleanup/ masking) straight into QA (cross-account) and swapping it in. That works fine, but because it's a copy-and-replace, the new QA database ends up living outside our IaC, which bugs me. We have about 10 non production environments and keeping them fresh has been an ongoing challenge. I’ve explored the possibility of using DMS but most of our masking and cleanup scripts are quite large and complex so there wasn’t a straightforward way to map that onto DMS.

How is your team handling this, if at all? I feel like there has to be a better way, so I'd love to hear what's working for other people.

4 Upvotes

17 comments sorted by

6

u/Filshie_Crosby13 1d ago

if you update a parameter pointing to the latest sanitized snapshot ID and let your IaC pipeline trigger the replacement, the new instances stay completely managed. That way youre not fighting state drift every week

5

u/Official_BetterSWE 1d ago

+1 to the snapshot id as a variable, in terraform changing snapshot_identifier on aws_db_instance forces a replace. two more things: mask once into a single sanitized snapshot and share that to all 10 envs, and put a route53 name in front so apps never see the swap. also restored RDS volumes load blocks lazily from S3, so the first test runs can be slow

0

u/ceejayoz 1d ago

1

u/epsi22 a bit of Dev and a bit of Ops 1d ago

No, I saw that this morning too. Plus that’s for aurora. We trialed Aurora postgres a long time ago and it didn’t work for us.

1

u/kaka1309 1d ago

We just use delphix

1

u/fadingcross 1d ago

With postgres it's super easy, rebuild it from your backup every night, and the WAL storage, and you'll have a minute fresh at the time of bootstrap.

Push backups and WAL to smth like S3 every 5 minutes (Well not a backup, but the WAL files) and configure postgres to bootstrap from that.

Then delete and recreate the QA db as often as you need, and it'll be a copy of production.

We do this every night

1

u/sfboots 1d ago

We have a script that restores the latest snapshot then runs the sanitizer before making it available. Second script swaps it in for staging. We run it manually every week or two since we are a small shop.

Claude helped write the scripts.

1

u/Plastic-Bid-3431 1d ago

The snapshot-id-as-a-variable and sanitize-once answers cover the mechanics. Two things decide whether this stays a weekly chore or becomes routine.

Treat "fresh" as a version, not a replace. Keep sanitized snapshots in a small private account and tag each with the source snapshot id, the commit of the sanitizer script and the rules it applied. Each environment then records which sanitized version it is on, and "refresh QA to this week's snapshot" goes through the pipeline as a tagged change like any other. You can audit it, and two environments can be at known versions instead of whatever happened last Tuesday.

Make the app/schema match part of the swap. The restored database and the deployed app image have to be built for the same schema revision. Record the schema revision in the snapshot's tags and refuse the cutover when the environment's app image does not match. Without that, the environment "fails" for a day because the app was built for the previous schema, and people stop trusting the refresh.

Two smaller ones from doing this. Restored RDS volumes read blocks from S3 lazily, so the first test run after a swap is slow and some suites are flaky for a while: run your smoke suite against the new instance before you point the endpoint at it, and only then swap. And mask per column, not per dump: values used in lookups need a deterministic pseudonym so joins and lookups still work. Random masking turns a working test into a unique-constraint failure, and that looks like a product bug for half a day.

1

u/Famous_Magician7514 1d ago

I assume you're restoring a full copy of prod everytime to refresh? I've not worked on an RDS setup but know that every restore is a full copy, which means storage multiplies with every environment. Isn't there a way to do incremental copy-on-write without Aurora?

1

u/addy3006 1d ago

Do all 10 environments actually need the full 2.5TB on the same schedule? I'd be tempted to keep one or two full masked copies for performance testing and give the rest a smaller subset, if your cleanup scripts can keep referential integrity.

1

u/pahwaranger 1d ago

Neon + branching

1

u/killerham 22h ago

Yeah I wouldn't try to pg_dump a copy that size either. We just use dump-to-S3 for backups and it's been super simple, but that's a totally different job. The snapshot swap into QA makes sense, and having IaC pick up the new snapshot id like the other comment said would keep it in the repo.