Convert from SQLite to PostgreSQL

529 views
Skip to first unread message

TM Co

unread,
Jun 28, 2021, 4:33:20 PM6/28/21
to Orthanc Users
Hi everyone. I uploaded a bunch of DICOMs onto an Orthanc server and I did so using SQLite, however, I would prefer to use PostgreSQL. Is there an easy way to move the files over other than uploading the files again since that would take way to long. Thank you.

Sébastien Jodogne

unread,
Jun 29, 2021, 12:59:14 AM6/29/21
to Orthanc Users
Hello,

The only official procedure is to reimport the "OrthancStorage" (if you have direct access to the filesystem), or to use the "Replicate.py" script to duplicate from one running instance of Orthanc to another using the REST API:

That being said, the SQLite and the PostgreSQL database schemas are so close to each other than it should be fairly easy to make a SQL import/export between them, e.g.:

You could start Orthanc with a PostgreSQL database so as to properly initialize an empty database (including triggers), then stop Orthanc and import the data by tools such as above. Make sure *not* to overwrite the content of the "GlobalProperties" table, as it contains system values. There could also be a challenge with AUTOINCREMENT columns.

If you have success with such a procedure, please contribute to Orthanc by sharing your story with the community. This could be useful to many people.

Regards,
Sébastien-

TM Co

unread,
Jun 29, 2021, 2:04:29 PM6/29/21
to Orthanc Users
Would I be able to do the second method you suggested if I'm using Docker containers? I currently have a Docker container for Orthanc and one for PostgreSQL.

Sébastien Jodogne

unread,
Jun 30, 2021, 1:05:29 AM6/30/21
to Orthanc Users
Nothing would prevent you from doing so.

James Howard

unread,
Oct 17, 2022, 4:35:42 AM10/17/22
to Orthanc Users
Just to say I had no success doing an SQLite to Postgres migration at the database level - even once I'd solved the issues with not overwriting the GlobalProperties tag and ensuring many of the integer tags in other tables are bigints.

In the end I ended up reworking the ImportDicomFiles.py script so that it is better suited towards a database migration and an order of magnitude faster: https://gist.github.com/jphdotam/21581fc4a205072ecf30d2c0c846f117

Reply all
Reply to author
Forward
0 new messages