Bit of a strange title, I know. Usually it would be someone with nefarious intent trying to delete your database... why would you want to do it?
Well, I've been doing a lot of Mastodon testing, which required a lot of repetition of steps. Running the Mastodon Ruby installer again throws errors because the previous database still exists, so how do you drop it?
Firstly, you need to stop Mastodon, otherwise the services still accessing the database will cause an error:
dropdb: error: database removal failed: ERROR: database "mastodon_production" is being accessed by other users
Stop Mastodon components with the following command (the asterisk is a wildcard character so will cause all matching mastodon services to be stopped):
sudo systemctl stop mastodon*
Secondly, switch to the user that runs Mastodon (if you followed the official instructions, this will be 'mastodon':
sudo su - mastodon
You've dropped your database! Congratulations...maybe? If you know a better way to do this (either using the Mastodon tools, or and better way in the Postgres CLI, please leave a comment, or let me know over at @techbitsio.