Search code examples
marklogic

What is the best way to delete more than 100,000 files?


I am struggling to delete large number of files loaded in a MarkLogic database. The number of files in a directory that I want to delete is more than 100,000. I usually use two following ways to delete files in query console. Each and every file in the directory is indexed.

for $x in xdmp:directory("/English/","infinity")
return xdmp:document-delete(fn:document-uri($x))

and

xdmp:directory-delete("/English/")

When I execute the any of the above method, I am getting "Time limit exceeded" which breaks the operation.

My question is

  1. Is there any other better way to delete a bunch of files?
  2. If not, is there any way to ignore XDMP-EXTIME or SVC-EXTIME?

Solution

  • If you can clear the forest(s), that is often faster than deleting large numbers of documents.

    Otherwise xdmp:directory-delete is generally the better technique, but for best performance ensure that the following conditions are met:

    1. The database configuration has directory-creation=manual.
    2. The database has no triggers.
    3. The database has no lock fragments.

    If those conditions are met then the bottleneck for deletes is usually locking, so you might consider turning that off temporarily.