Best practices Erasing all studies?

In an environment of intense use of Orthanc and with little storage …
What would be the best practice mechanism to erase every X time, the index and the associated directories within OrthancStorage.
Assuming I’m using Orthanc-1.3.2 and the native database engine (SQLite)

Something rudimentary that I came up with is a script where I stop the Orthanc, delete everything in OrthancStorage (index and directories) and then start the service again.

But maybe it is not the safest and most efficient way

Thank you

Your solution is correct and easy to implement.

If you have limited storage you may just want to use

  // Maximum size of the storage in MB (a value of "0" indicates no
  // limit on the storage size)
  "MaximumStorageSize" : 0,

Older patients will be deleted automatically when you get close to the maximum storage size.


I would personally favor Alain’s solution, as it prevents the downtime of Orthanc, and as it allows to give a strict upper limit on the disk space that will be used by Orthanc at any time.


Thank you very much Alain and Sebastien, a pleasure as always

Best regards


I have a question regarding this solution, how does the software determine what stays and what goes? In my use case, I was tasked with removing all patients that have not had new studies in over 3 months. For example, say a patient is the oldest one but it has received new studies recently. Which of the following statement is true when the MaximumStorageSize is reached?

  1. Only the oldest studies are deleted.
  2. The whole patient is deleted, including the recent studies.
  3. Nothing is deleted from this patient and the next patient with the oldest studies is deleted instead.

I’m hoping that #3 is the current behavior but I’m fairly certain it will be #1 or 2 and would just like confirmation.

If it is as I suspect, what would be my possible solutions in implementing some sort of script that checks the patient’s latest entry and deletes anything that has over X months of age? Is LUA even an option or is the REST-API my only bet? I have very limited programming knowledge. My background is mostly in sysadmin work (PowerShell/bash scripting) so the simpler it is, the better, but I’m not afraid to learn.

Thanks for your time!

Hi Mat,

Actually, you’re lucky, option 3 is the one that is implemented since the correction of this issue:

The orthanc book was not correct according to that. I’ll update it immediately:

Best regards,


Awesome!! Thanks for the info. You just made my day. :slight_smile:

I actually plan on doing something similar where after 3 months studies are purged from Orthanc, Out of curiosity how are you implementing this? I planned on using the REST API within Orthanc to delete resources.

Hi Richard,

I’ve simply gone and used the MaximumStorageSize option with enough leeway so that it would not be an issue. On this particular instance, ~150 GB of data is actually about a year of use and there was no requirement for absolutely getting rid of the data after 3 months, it was more a storage concern where it would fill up if left to its own devices so I set it to 200 GB and forgot about it. I have yet to fill it up completely after nearly a year and a half of use.

Sorry, I know it isn’t a very elegant or accurate solution and may not help you at all though if you do end up developing something on your end, please let me know!


Note that there are many samples about how to use the REST API in Python, in the Orthanc source distribution:

Hi Richard

I recently faced the same problem and came with a solution that worked pretty fine.

I found a python script that deleted all studies and another that uses a time range filter at Sebastien repository -

So I combined these two scripts to be able to delete only studies within a specific date range.

If you want to try I may send it to you