Deleting a user account

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

Users can be deleted from a GitLab instance, either by:

  • The user themselves.
  • An administrator.
note
Deleting a user deletes all projects in that user namespace.

Delete your own account

History
  • Delay between a user deleting their own account and deletion of the user record introduced in GitLab 16.0 with a flag named delay_delete_own_user. Enabled by default on GitLab.com.
On self-managed GitLab, by default this feature is not available. To make it available, an administrator can enable the feature flag named delay_delete_own_user. On GitLab.com, this feature is available. On GitLab Dedicated, this feature is not available.

As a user, to delete your own account:

  1. On the left sidebar, select your avatar.
  2. Select Edit profile.
  3. On the left sidebar, select Account.
  4. Select Delete account.
note
On GitLab.com, there is a seven day delay between a user deleting their own account and deletion of the user record. During this time, that user is blocked and a new account with the same email address or username cannot be created. Accounts with no issues, comments, notes, merge requests, or snippets are deleted within an hour. Accounts under paid namespaces are deleted within an hour.

Delete users and user contributions

Tier: Free, Premium, Ultimate Offering: Self-managed, GitLab Dedicated

As an administrator, to delete a user account:

  1. On the left sidebar, at the bottom, select Admin.
  2. Select Overview > Users.
  3. Select a user.
  4. Under the Account tab, select:
    • Delete user to delete only the user but maintain their associated records. You can’t use this option if the selected user is the sole owner of any groups.
    • Delete user and contributions to delete the user and their associated records. This option also removes all groups (and projects within these groups) where the user is the sole direct Owner of a group. Inherited ownership doesn’t apply.
caution
Using the Delete user and contributions option may result in removing more data than intended. See associated records for additional details.

Associated records

When deleting users, you can either:

  • Delete just the user, but move contributions to a system-wide “Ghost User”:
    • The @ghost acts as a container for all deleted users’ contributions.
    • The user’s profile and personal projects are deleted, instead of moved to the Ghost User.
  • Delete the user and their contributions, including:

In both cases, commits retain user information and therefore data integrity within a Git repository.

An alternative to deleting is blocking a user.

When a user is deleted from an abuse report or spam log, these associated records are always removed.

The deleting associated records option can be requested in the API as well as the Admin area.

caution
User approvals are associated with a user ID. Other user contributions do not have an associated user ID. When you delete a user and their contributions are moved to a “Ghost User”, the approval contributions refer to a missing or invalid user ID. Instead of deleting users, consider blocking, banning, or deactivating them.

Delete the root account on a self-managed instance

Offering: Self-managed
caution
The root account is the most privileged account on the system. Deleting the root account might result in losing access to the instance Admin area if there is no other administrator available on the instance.

You can delete the root account using either the UI or the GitLab Rails console.

Before you delete the root account:

  1. If you have created any project or personal access tokens for the root account and use them in your workflow, transfer any necessary permissions or ownership from the root account to the new administrator.
  2. Back up your self-managed instance.
  3. Consider deactivating or blocking the root account instead.

Use the UI

Prerequisites:

  • You must be an administrator for the self-managed instance.

To delete the root account:

  1. In the Admin area, create a new user with administrator access. This ensures that you maintain administrator access to the instance whilst mitigating the risks associated with deleting the root account.
  2. Delete the root account.

Use the GitLab Rails console

caution
Commands that change data can cause damage if not run correctly or under the right conditions. Always run commands in a test environment first and have a backup instance ready to restore.

Prerequisites:

  • You must have access to the GitLab Rails console.

To delete the root account, in the Rails console:

  1. Give another existing user administrator access:

    user = User.find(username: 'Username') # or use User.find_by(email: 'email@example.com') to find by email
    user.admin = true
    user.save!
    

    This ensures that you maintain administrator access to the instance whilst mitigating the risks associated with deleting the root account.

  2. To delete the root account, do either of the following:

    • Block the root account:

      # This needs to be a current admin user
      current_user = User.find(username: 'Username')
      
      # This is the root user we want to block
      user = User.find(username: 'Username')
      
      ::Users::BlockService.new(current_user).execute(user)
      
    • Deactivate the root user:

      # This needs to be a current admin user
      current_user = User.find(username: 'Username')
      
      # This is the root user we want to deactivate
      user = User.find(username: 'Username')
      
      ::Users::DeactivateService.new(current_user, skip_authorization: true).execute(user)
      

Troubleshooting

Deleting a user results in a PostgreSQL null value error

There is a known issue that results in users not being deleted, and the following error generated:

ERROR: null value in column "user_id" violates not-null constraint

The error can be found in the PostgreSQL log and in the Retries section of the background jobs view in the Admin area.

If the user being deleted used the iterations feature, such as adding an issue to an iteration, you must use the workaround documented in the issue to delete the user.