How do I remove a user directory from Confluence via the database?
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
Purpose
You may run into an error while trying to remove a directory from Confluence. In this situation, manually removing the directory via the database is the only workaround.
Solution
Always backup your data before performing any modifications to the database.
First, navigate to Confluence Admin >> User Directories and move the directory that you want to remove to the bottom of the directory list. Then, shutdown Confluence and run the following commands in the Confluence database:
Run this query to identify the directory id of the directory you are trying to remove:
SELECT * FROM cwd_directory;
Run these commands to remove the directory, one by one, in the order below (replace <directoryId> with the directory's id from the query above)
DELETE FROM cwd_app_dir_operation WHERE app_dir_mapping_id IN (SELECT id FROM cwd_app_dir_mapping WHERE directory_id = <directoryid>);
DELETE FROM cwd_app_dir_mapping WHERE directory_id = <directoryid>;
DELETE FROM cwd_directory_attribute WHERE directory_id = <directoryid>;
DELETE FROM cwd_membership WHERE parent_id IN (SELECT id FROM cwd_group WHERE directory_id = <directoryID>) OR child_group_id IN (SELECT id FROM cwd_group WHERE directory_id = <directoryID>) OR child_user_id IN (SELECT id FROM cwd_user WHERE directory_id = <directoryID>);
DELETE FROM cwd_group WHERE directory_id = <directoryID>;
DELETE FROM cwd_user_attribute WHERE directory_id = <directoryID>;
DELETE FROM cwd_user WHERE directory_id = <directoryID>;
DELETE FROM cwd_directory_operation WHERE directory_id = <directoryID>;
DELETE FROM cwd_synchronisation_status WHERE directory_id = <CROWD_directoryID>;
DELETE FROM cwd_directory WHERE id = <directoryID>;
Check the list_index column of the cwd_app_dir_mapping table.
select list_index,id from cwd_app_dir_mapping;
Ensure that the number for the list_index column is in a proper numerical order. For example, the result below show the list_index which are not in the proper numerical order. As you can see, the list_index contain the number 0,3 and 1. The number
2
is missing.list_index
id
0 214324324 3 353453456 1 435456556 If the you see the following, please update the list_index to the proper order.
update cwd_app_dir_mapping set list_index = <number> where id = <directory_id>
After updating the proper list_index should look like the following:
list_index
id
0 214324324 2 353453456 1 435456556 - Start Confluence.