Restoring to the Safe Timestamp
- Last Updated: April 15, 2026
- 2 minute read
- MarkLogic Server
- Version 11.0
- Documentation
If you want to restore as much data as possible, you can restore your data to the minimum safe timestamp.
For example, the database you want to restore has four forests, as shown below. You use the xdmp:host-status function to locate the safe-restore-to-time value, which is earliest of the four last-commit timestamps. In this example, the safe-restore-to-time is the timestamp of the last committed transaction in Forest A.

The following procedure describes how to restore to the minimum timestamp using the XQuery API.
Note:
This same procedure can be done using the Admin Interfaces described in Setting Merge Policy, Admin Interface for Database Restore, and Rolling Back a Transaction.
-
Use the
admin:database-get-merge-timestampfunction to get the current merge timestamp. Save this value so it can be reset after you have completed the rollback operation. -
Use the
admin:database-set-merge-timestampfunction to set the merge timestamp to any time before your minimum safe timestamp. This will preserve fragments in merge after this timestamp until you have rolled back your forest data. -
Use the
xdmp:database-restorefunction with$journal-archivingset tofn:true()and$restoreToTimeset tonull( )to restore the database to the latest timestamp. -
After the restore operation has completed, use the
xdmp:forest-rollbackfunction to roll back the forests to thesafe-restore-to-timetimestamp returned by thexdmp:host-statusfunction.For example, if you are restoring the Documents database, you can use the following query to rollback your forest data:
xquery version "1.0-ml"; declare namespace host = "http://marklogic.com/xdmp/status/host"; let $timestamp := xdmp:wallclock-to-timestamp( xs:dateTime(xdmp:host-status(xdmp:host("your-host.com")) /host:restore-jobs/host:restore-job/host:safe-restore-to-time /fn:data(.))) return xdmp:forest-rollback( xdmp:database-forests(xdmp:database("Documents")), $timestamp) -
Use
admin:database-set-merge-timestampfunction to set the merge timestamp back to the value you saved in Step 1.