Installation and Administration

Garbage-Collecting Orphaned Binaries

Updated: October 16, 2020

The binary files attached to documents are not stored in the database but using a specialized binary store (typically filesystem-based or S3), and are not removed like documents (see Deleting Documents).

Binary files are not immediately deleted when their containing document is deleted because the binary store uses a de-duplication strategy which means that the same binary file may be referenced by several documents. To avoid complex locking or reference counting strategies, they are simply garbage-collected when there remains no reference to them (they are orphaned).

Manually (using the Web interface)

The garbage collection is done by an explicit administration step:

  1. Go to Admin > System Information > Repository binaries.
  2. Check the Delete orphaned binaries check box. If you just want to gather statistics about what it going to be deleted, don't check this box and go next step.
  3. Click on Mark orphaned binaries.

Programmatically (Using the Nuxeo Shell or Java Code)

https://github.com/nuxeo/nuxeo/blob/master/nuxeo-distribution/nuxeo-distribution-resources/src/main/resources/templates-tomcat/common-base/client/scripts/deleteOrphanBinaries.groovy
import org.nuxeo.ecm.core.storage.binary.BinaryManagerStatus;
import org.nuxeo.ecm.core.storage.sql.management.SQLRepositoryStatus;
import org.nuxeo.ecm.core.storage.sql.management.SQLRepositoryStatusMBean;
SQLRepositoryStatusMBean status = new SQLRepositoryStatus();
if (!status.isBinariesGCInProgress()) {
    BinaryManagerStatus binaryManagerStatus = status.gcBinaries(true);
    println("Orphaned binaries garbage collecting result: " + binaryManagerStatus.getNumBinariesGC());
} else {
    println("Orphaned binaries garbage collecting is already in progress.");
}

Related Documentation

Deleting Content (User documentation) Managing Deleted Documents (User documentation) Deleting Documents (Developer documentation) How to Enable the Trash Feature (Developer documentation)