Hi,
I try to clean up our seafile database. We have more than 26.000 inactive users in the ccnet_db.LDAPUsers table. Most of them are ex-students who left university.
If I delete an inactive user from seafile, it seems that not all references to this user are deleted from the database tables. I deleted a user who was inactive for more than 10 years. His libraries have been deleted, but I found out, that there are still 131 entries in the table seahub_db.share_fileshare. The table has 61.000 entries, the oldest are from 2013.
How can these (and other) data be cleaned up, when a user is deleted?
Thanks,
Dirk
Please note the table ccnet_db.LDAPUsers (and its related table ccnet_db.LDAPImported) is no longer used since Seafile version 11.0 .
In version 11.0, Seafile underwent a major architectural change regarding LDAP integration:
- Reimplementation: LDAP authentication was moved from the C-based
ccnet-server component to the Seahub Python codebase .
- User Storage: LDAP users are now stored directly in the
ccnet_db.EmailUsers table alongside regular users, rather than in separate LDAP-specific tables .
- Mapping: A new mapping system was introduced using the
social_auth_usersocialauth table to link external LDAP identifiers to internal Seafile user IDs .
When upgrading to version 11.0 or later, administrators are required to run the migrate_ldapusers.py script to merge data from the old LDAP tables into ccnet_db.EmailUsers . After this migration, the old tables like LDAPUsers or LDAPImported remain in the database as legacy/obsolete data and can technically be cleaned up once the migration is confirmed successful.
Seafile includes a management command specifically designed to clear records for libraries that no longer exist in the system. This command likely covers the share_fileshare table because it is indexed by repo_id.
Run the following command inside the Seafile server directory (or inside the Docker container):
./seahub.sh python-env python3 seahub/manage.py clear_invalid_repo_data
Note: You can use --dry-run=true first to see how much data will be removed without actually deleting it
Manual Cleanup (If necessary)
If the management commands do not clear the specific entries in share_fileshare, it may be because the repo_id still exists in some form or the command doesn’t target that specific table for user-based deletion. You can manually identify and remove these records using SQL:
DELETE FROM share_fileshare WHERE username NOT IN (SELECT email FROM EmailUser);
See more at Clean database - Seafile Admin Manual
Hi Daniel,
thanks for the reply. We are in the process of upgrading Seafile from 11 to 13. I thought it was a good idea to clean up the database first. Or should we upgrade first, and delete the old records later?
Dirk
There are no known issues regarding database cleanup in version 11.0. Both ways are okay as long as you backup the database first.