Delete space failed error when trying to delete a space within Confluence 5.6.x or older versions
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
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
PLEASE READ: As with all recommendations made by Atlassian Support, please follow best practices for Change Management and *test and validate* these settings in a Test/Development and Staging environment prior to rolling any changes into a Production environment. This is to validate these changes and ensure that they will function well within your infrastructure prior to placing these changes in production.
Confluence 5.7.x or later: In case we need to remove a space from the database after a failed space delete, please, follow this KB instead.
Environment
Confluence 5.6.x and older versions.
Problem
The error "Delete space failed" is shown in the user interface when a user tries to delete a space within Confluence. The following appears in the atlassian-confluence.log
ERROR [Long running task: Space removal long running task] [atlassian.event.internal.AsynchronousAbleEventDispatcher] run There was an exception thrown trying to dispatch event 'com.atlassian.confluence.event.events.space.SpaceWillRemoveEvent[source=com.atlassian.confluence.spaces.DefaultSpaceManager@4836e98b]' from the invoker 'SingleParameterMethodListenerInvoker
...
action: doremovespace
java.lang.RuntimeException: Hibernate operation: could not delete: [com.atlassian.confluence.pages.Attachment#]; SQL []; ORA-02292: integrity constraint (WIKI.FK9DC3E34D34A4917E) violated - child record found
; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (WIKI.FK9DC3E34D34A4917E) violated - child record found
Cause
There are still some attachment references in the attachmentdata table relating to the space getting deleted. This causes the following constraint to fail:
ALTER TABLE attachmentdata
ADD CONSTRAINT fk9dc3e34d34a4917e FOREIGN KEY (attachmentid)
REFERENCES content (contentid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
Workaround
The workaround is to delete these related entries in the attachmentdata table prior to running the delete function. Since you are planning to delete the space, deleting the related entries will make sure the constraint does not fail.
Note: Make sure to update the space key at the end of the query with the space key for the problematic space.
delete from attachmentdata where attachmentid in (select a.attachmentid from attachments a join content c on a.pageid=c.contentid join spaces s on c.spaceid=s.spaceid where s.spacekey='SPACEKEY');