Mastodon: Delete / Remove Account As Administrator

Created on 7 Apr 2017  路  8Comments  路  Source: tootsuite/mastodon

I saw pre-existing tickets regarding the ability for users to delete their accounts and I understand that is currently under review and possibly will be implemented. However from an Administrator's stand point, one who has access to the backend of the site as well as the psql database, does anyone know of a way to remove an account entirely? I will admit I'm very new to psql and with the help of Google I'm able to at least navigate my way through the database, but would like some assistance on removing an account. This particular use case is the user who signed up on my instance was simply testing out the UI and they left a Toot requesting their account be deleted.


  • [x] I searched or browsed the repo鈥檚 other issues to ensure this is not a duplicate.

Most helpful comment

For my single user instance with a second testing account, I did:

delete from users WHERE email='[email protected]';
delete from accounts WHERE username='testing';
select setval('users_id_seq', 1);

Note that the integer in the select setval needs to be the highest id in the users table (after the deletion). If the account you're deleting isn't the highest ID, don't do that query.

Also note that the user count on the about/more page appears to only reflect the users_id_seq value, rather than a count of the rows in the user table. For this to work in the general case, that code needs to be updated.

All 8 comments

Also, considering several country laws, an instance must be able to remove user data on request.

Such function is called "suspend" in the admin UI. "Perform full suspension" (or "suspend" on reports) deletes all of the user's data except the account entry (preserved username) and user entry (e-mail, password). Suspended accounts cannot login.

However, there are cases where you'd want to free up a username or e-mail address. In very rare cases, when such an action wouldn't cause future username collisions.

Thanks for the explanation on that @Gargron, I was able to successfully perform a full suspension which seems to have wiped most of the data. The only issue is as you stated, it preserves the username, email, and password hash. I'd like to be able to remove all that as well, again from the Admin side of things. The Full Suspension also doesn't have any effect on the /about/more information - so it says I have X amount of users when I really don't since I performed a suspension on one.

It would probably be pretty easy to add a button to perform the three SQL queries to remove the user and update the counter yeah

Thanks @wxcafe. Until it gets added, do you mind pasting the queries here?

For my single user instance with a second testing account, I did:

delete from users WHERE email='[email protected]';
delete from accounts WHERE username='testing';
select setval('users_id_seq', 1);

Note that the integer in the select setval needs to be the highest id in the users table (after the deletion). If the account you're deleting isn't the highest ID, don't do that query.

Also note that the user count on the about/more page appears to only reflect the users_id_seq value, rather than a count of the rows in the user table. For this to work in the general case, that code needs to be updated.

Also note that the user count on the about/more page appears to only reflect the users_id_seq value, rather than a count of the rows in the user table. For this to work in the general case, that code needs to be updated.

No, this is wrong. It does count. It does not use max ID. But the value is cached for a time.

Hi all,

I'm looking for a solution to completely delete a user (I know the problems it causes) so to summarize, am I doing it right?

sudo -u postgres psql
\c mastodon_production;

SELECT * FROM users WHERE email='[email protected]';
DELETE FROM users WHERE email='[email protected]';

SELECT * FROM accounts WHERE username='usertoremove';
DELETE FROM accounts WHERE username='usertoremove';
SELECT setval('users_id_seq', 1); # only if its the last registered user you want delete
\q

Thank you for the help
Best regards.

Was this page helpful?
0 / 5 - 0 ratings