How do I remove a user directory from Confluence via the database?

Still need help?

The Atlassian Community is here for you.

Ask the community

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:

  1. Run this query to identify the directory id of the directory you are trying to remove:

    SELECT * FROM cwd_directory;
    
  2. 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_directory WHERE id = <directoryID>;
    
  3. 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
  4. Start Confluence.
Last modified on Feb 26, 2016

Was this helpful?

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