Live data from Hacker News

We deleted the production database by accident

keepthescore.co

21–30 of 456 posts

Re: We deleted the production database by accident

#21
post #15
post #11

localhost is an abstraction, it's a non-routable-outside-your-machine network...except it's not. It's nothing more than normal TCP traffic except with a message to the OS and other programs that whatever is on that local computer network, you don't want it routed outside the local computer. There's absolutely nothing stopping anything with access to localhost from routing it anywhere that process wants. Does not even…

The fact that the production db has the same username/password as the development one is perhaps more troubling.

It likely doesn't... it probably reads it from the environment or a config role, and since it was in production it had the production credentials.

Re: We deleted the production database by accident

#22
post #15
post #11

localhost is an abstraction, it's a non-routable-outside-your-machine network...except it's not. It's nothing more than normal TCP traffic except with a message to the OS and other programs that whatever is on that local computer network, you don't want it routed outside the local computer. There's absolutely nothing stopping anything with access to localhost from routing it anywhere that process wants. Does not even…

The fact that the production db has the same username/password as the development one is perhaps more troubling.

Yes! This is the biggest mistake probably

Re: We deleted the production database by accident

#23
post #13

>Note that host is hardcoded to localhost. This means it should never connect to any machine other than the developer machine. We’re too tired to figure it out right now. The gremlins won this time. Obviously, somehow the script ran on the database host. some practices I've followed in the past to keep this kind of thing from happening: * A script that deletes all the data can never be deployed to production. * scrip…

I have a little metadata table in production that has a field that says “this is a production database”. The delete-everything script reads that flag via a SQL query that will error out of it’s set in the same transaction as the deletion. To prevent the flag from getting cleared in production, the production software stack will refuse to run if the “production” flag is not set.

Nice. Very nice.

Re: We deleted the production database by accident

#25

>Note that host is hardcoded to localhost. This means it should never connect to any machine other than the developer machine. We’re too tired to figure it out right now. The gremlins won this time. Obviously, somehow the script ran on the database host. some practices I've followed in the past to keep this kind of thing from happening: * A script that deletes all the data can never be deployed to production. * scrip…

The blog mentions it's a managed DigitalOcean database, so the script likely wasn't run on the host itself.

More likely, I'd suspect, is something like an SSH tunnel with port forwarding was running, perhaps as part of another script.

Re: We deleted the production database by accident

#26

Lost seven hours of data? Daily backup with no transaction log backup? Whoa.

Yeah, this. The problem is not that the production database was deleted by accident. The problem is that it was possible to (unrecoverably) delete the production database by accident.

Re: We deleted the production database by accident

#27
post #15

Earlier quoted context omitted.

The fact that the production db has the same username/password as the development one is perhaps more troubling.

It likely doesn't... it probably reads it from the environment or a config role, and since it was in production it had the production credentials.

The code explicitly referenced “DevelopmentConfig” though

Re: We deleted the production database by accident

#29
post #16

This is my greatest fear when it comes to terraform: > terraform destroy (And either a confirmation or a flag) and everything is deleted. I know you can add some locks but still :/

You can save yourself from scary operations like deleting everything by a.) not rooting your entire infra in the same main.tf and b.) using Terraform's lifecycle meta-argument: https://www.terraform.io/docs/configuration/resources.html#l...

I like to use the lifecycle feature for suuuper core things that will never be deleted (VPC, r53 zone, etc) and eventually when I start targeting multiple DCs w/ lots of infra I'll eventually move to many state roots (or use tools like Terragrunt, which make things mildly scary again).

Re: We deleted the production database by accident

#30

> Computers are just too complex and there are days when the complexity gremlins win. Wow. But then again it's not like programmers handle dangerous infrastructure like trucks, military rockets or nuclear power plants. Those are reserved for adults

I feel that computers make it easier for this danger to be more indirect, however. The examples you give are physical, and even the youngest of child would likely recognise they are not regular items. A production database, meanwhile, is visually identical to a test database, if measures are not made to make it distinct. Adults though we may be, we're human, and humans can make really daft mistakes without the right context to avoid them
Post reply on HN