2019-01-30-removing-masto-usernames-from-postgresql.md

 1---
 2layout: post
 3title: Removing Masto usernames from PostgreSQL
 4subtitle: Give a Mastodonian their handle back
 5description: Give a Mastodonian their handle back
 6tags: mysql cli sysadmin
 7cover: /assets/posts/mastodon.png
 8date: 2019-01-30 13:16 -0500
 9---
10The other day, I had a friend of mine create an account on [my Mastodon instance](https://masto.nixnet.xyz/). I made him an admin account thinking I'd have the _ability_ to demote him if I needed to only to find that I couldn't. So I had him delete his account thinking that he'd be able to remake it with the same username only to find that he couldn't. This is the username he uses everywhere (like me with Amolith) so I wanted to get it back for him. I did some digging and found that I would have to delete the handle from Masto's PostgreSQL database. I'd never used postgres before so it was very new; a rundown of the basic commands is below along with the one I used to delete his username at the end.
11
12***NOTE:*** I don't know how this will affect your instance if the user had toots before they deleted their account. Handles federate from instance to instance and things could very well break if another instance had the user's information already. Thankfully, my friend was busy that day and hadn't even started configuring his account, much less tooted anything.
13
14# PostgreSQL Syntax
15`\l` - list databases
16`\c <database>` - change databases
17`\d` - list tables
18`\d+ <table>` - list columns in the specified table
19`select <column> from <table>;` - show the entries in the specified column
20`delete from <table> where <column> = '<user_handle>';` - delete the username
21
22The command sequence I used was:
23`\c mastodon`
24`delete from accounts where username='<handle>';`