How to Delete the Mastodon PostgreSQL Database

How to Delete the Mastodon PostgreSQL Database
Photo by Sunder Muthukumaran / Unsplash

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

Thirdly/lastly run:

dropdb mastodon_production

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.



Great! Next, complete checkout for full access to techbits.io
Welcome back! You've successfully signed in
You've successfully subscribed to techbits.io
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated