- read only connections / users in general
- append _prod / _stage to the database name to avoid ambiguity (and ensure psql is configured to show the database name at the prompt)
- configure editors to color code sessions where possible (red for prod, amber for stage and green for dev/local)
- if a manual data modification is necessary, use a transaction and have commands prewritten to verify the intended outcome
In terms of underlying infrastructure I also very much appreciate deletion protection in terraform providers for any data stores, forcing a two phase destruction (one plan/apply to disable the protection and a second to actually destroy)
Someone suggested we restore the database from its last backup (which we do daily with a few weeks retention), then do a "SELECT INTO FROM" to re-fill the table. We lost a couple hours of data and were soon back online.
I am sure there are more nuggets to take away from this story, but I took: always maintain a robust set of backups and let people know about the problem so you can at least try to work out a solution.
I realized that Fdisk wasn’t using the units my muscle memory had memorized, but not until I rebooted and everything was dead.
My manager and I decided we’d record it as an unplanned backup restore test and got to check some compliance boxes.
Yay backups! The lesson stuck and I got to learn it without consequences! Many are not that lucky.
My own story would be ... "The day I wiped a production database .. completely .. on Christmas eve."
BTW: The table was from an insurance company and ~all sent in accidents from that day where deleted, around 500 "customers"...sweaty palms is an understatement.
The restore process should be written in an incident response run book and practiced by the on-call people. (Maybe in your quarterly disaster recovery tests?) The terror of data loss fades significantly when you come across a clean, one page restore process and you’re able to get the data back without a lot of effort.