Finding Jira comments that prevent user deletion

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

When administering Jira instances, you may need to delete an existing user account, however, as per our documentation on Deleting Jira Users, a user can't be entirely deleted if it has lingering references in existing Jira issues, such as commenting or having assigned issues.

While assigned issues can easily be identified through a link provided during the deletion attempt, such a listing is not provided for comments, difficulting the removal process, should inactivating the account not be an option.

Example of user deletion attempt:

In the past, a suggestion was logged to implement this functionality in Jira, however, due to low traction, it was chosen not to be implemented into the main product. 

So this article aims to cover this gap and help administrators complete this task.

Environment

  • Jira Data Center/Server.

Solution

Since no native function exists in JQL to specifically search for comments, we'll need to search for the comments directly in the Jira database to identify these lingering references.

To do so, we can utilize the select statement below while making sure to change <lowercase_username> the actual username (all in lowercase) that you are looking into deleting.

(info) The SQL queries below were written and tested on a Postgres database, however, they can be easily adjusted to other database syntaxes should it be necessary.

SELECT ja.id as CommentID, CONCAT(pj.pkey, '-', ji.issuenum) as IssueKey, pj.pname as ProjectName, au.lower_user_name as CommentAuthor, ja.actiontype, ja.actionbody, ja.created
FROM jiraaction ja
LEFT OUTER JOIN jiraissue ji ON ja.issueid = ji.id
LEFT OUTER JOIN project pj ON ji.project = pj.id
LEFT OUTER JOIN app_user au ON ja.author = au.user_key
WHERE au.lower_user_name = '<lowercase_username>'
AND ja.actiontype = 'comment';

(lightbulb)About the results

The above query should inform you of all issues/projects that contain a comment by a given user, allowing you, as the administrator, to delete the comments in the UI should you choose.

If the IssueKey returns empty (as a single '-'), that specific comment has lost its relationship with the comment still stored on the database (usually occurring due to a failure in the issue deletion process). In that case, you can delete the comment directly from the DB with the following DELETE statement (while adjusting the <CommentID> with the actual CommentID received in the previous results):

DELETE FROM jiraaction WHERE id in ('<CommentID>');

(warning) Note about deleting orphaned comments in the database:

  • Atlassian recommends testing this process in a lower environment and taking a native database backup before executing this statement in production should rolling back the changes be necessary.
  • We also recommend only deleting comments through the database when there's no relationship with an issue. If given the option, always remove the data through the Jira UI.
Last modified on Feb 10, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.