Mercurial > hg > orthanc-book
changeset 154:365427cebb64
mysql
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Jul 2018 14:45:40 +0200 |
parents | 008091376e7a |
children | 498c9e42c99d |
files | Sphinx/source/faq/orthanc-storage.rst Sphinx/source/plugins.rst Sphinx/source/plugins/mysql.rst Sphinx/source/plugins/postgresql.rst Sphinx/source/users/backup.rst Sphinx/source/users/replication.rst |
diffstat | 6 files changed, 222 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/Sphinx/source/faq/orthanc-storage.rst Fri Jun 22 10:54:20 2018 +0200 +++ b/Sphinx/source/faq/orthanc-storage.rst Tue Jul 10 14:45:40 2018 +0200 @@ -7,11 +7,11 @@ -------------- **By default** (i.e. if no database plugin such as :ref:`PostgreSQL -<postgresql>` is used), Orthanc stores all the DICOM files it receives -in a folder called ``OrthancStorage`` on the filesystem. Orthanc also -associates each incoming DICOM file with a JSON file that summarizes -all its DICOM tags, which speeds up subsequent processing by avoiding -a costly DICOM parsing. +<postgresql>` or :ref:`MySQL <mysql>` is used), Orthanc stores all the +DICOM files it receives in a folder called ``OrthancStorage`` on the +filesystem. Orthanc also associates each incoming DICOM file with a +JSON file that summarizes all its DICOM tags, which speeds up +subsequent processing by avoiding a costly DICOM parsing. More generally, the ``OrthancStorage`` folder contains a set of so-called **attachments**, that may correspond to either a DICOM file, @@ -60,8 +60,9 @@ reasons: * This internal organization is only true when no database plugin is - used (e.g. the :ref:`PostgreSQL plugin <postgresql>` can be - configured to store the attachments inside a database). + used (e.g. the :ref:`PostgreSQL <postgresql>` and :ref:`MySQL + <mysql>` plugins can be configured to store the attachments inside a + database). * Orthanc can be configured to compress the attachments before writing them on the disk (cf. the ``StorageCompression`` option). * By directly reading the content of ``OrthancStorage``, you bypass
--- a/Sphinx/source/plugins.rst Fri Jun 22 10:54:20 2018 +0200 +++ b/Sphinx/source/plugins.rst Tue Jul 10 14:45:40 2018 +0200 @@ -19,8 +19,9 @@ * Replacing **the way DICOM images are decoded** (e.g. the official :ref:`Web viewer plugin <webviewer>` introduces the decoding of JPEG2000 images, which is not available in the core of Orthanc). -* Replacing the default **database back-end** of Orthanc (that is built - upon SQLite) by another (:ref:`PostgreSQL <postgresql>`, MySQL, SQL Server...). +* Replacing the default **database back-end** of Orthanc (that is + built upon SQLite) by another (:ref:`PostgreSQL <postgresql>`, + :ref:`MySQL <mysql>`, SQL Server...). * Creating **new REST APIs** on the top of the Orthanc built-in API (as in in the official :ref:`DICOMweb <dicomweb>` plugin). * **Reacting** to the arrival of new DICOM images or other @@ -53,6 +54,7 @@ From Osimis ^^^^^^^^^^^ +* :ref:`mysql` * :ref:`authorization` * `Osimis <http://osimis.io/>`__ maintains an evolution of the official Web viewer plugin. The Osimis plugin adds tools for
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sphinx/source/plugins/mysql.rst Tue Jul 10 14:45:40 2018 +0200 @@ -0,0 +1,162 @@ +.. _mysql: + + +MySQL/MariaDB plugins +===================== + +.. contents:: + +The Orthanc project provides two **official** plugins to replace the +default storage area (on the filesystem) and the default SQLite index +by a MySQL or a MariaDB database. + +For general information, check out the `official homepage of the +plugins <http://www.orthanc-server.com/static.php?page=mysql>`__. + + + +Compilation +----------- + +Static linking +^^^^^^^^^^^^^^ + +.. highlight:: text + +The procedure to compile these plugins is similar to that for the +:ref:`core of Orthanc <compiling>`. The following commands should work +for most UNIX-like distribution (including GNU/Linux):: + + $ mkdir BuildMySQL + $ cd BuildMySQL + $ cmake ../MySQL/ -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release + $ make + +The compilation will produce 2 shared libraries, each containing one plugin for Orthanc: + +* ``OrthancMySQLIndex`` replaces the default SQLite index of Orthanc by MySQL. +* ``OrthancMySQLStorage`` makes Orthanc store the DICOM files it receives into MySQL. + + +Microsoft Windows +^^^^^^^^^^^^^^^^^ + +Pre-compiled binaries for Microsoft Windows `are also available +<http://www.orthanc-server.com/browse.php?path=/plugin-mysql>`__. + + +Dynamic linking on Ubuntu 16.04 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. highlight:: text + +If static linking is not desired, here are build instructions for +Ubuntu 16.04 (provided build dependencies for the :ref:`core of +Orthanc <compiling>` have already been installed):: + + $ sudo apt-get install libmysqlclient-dev + $ mkdir BuildMySQL + $ cd BuildMySQL + $ cmake ../MySQL/ -DCMAKE_BUILD_TYPE=Release \ + -DALLOW_DOWNLOADS=ON \ + -DUSE_SYSTEM_GOOGLE_TEST=OFF \ + -DUSE_SYSTEM_ORTHANC_SDK=OFF + $ make + + +Usage +----- + +You of course first have to :ref:`install Orthanc <binaries>`, with a +version above 0.9.5. You then have to **create a database** dedicated +to Orthanc on some MySQL/MariaDB server. Please refer to the `MySQL +documentation +<https://dev.mysql.com/doc/refman/8.0/en/database-use.html>`__. + +.. highlight:: json + +Once Orthanc is installed and the database is created, you must add a +section in the :ref:`configuration file <configuration>` that +specifies the address of the **MySQL/MariaDB server together with your +credentials**. You also have to tell Orthanc in which path it can find +the plugins: This is done by properly modifying the ``Plugins`` +option. You could for instance adapt the following configuration +file:: + + { + "Name" : "MyOrthanc", + "MySQL" : { + "EnableIndex" : true, + "EnableStorage" : true, + "Host" : "localhost", // For Windows or network connections + "Port" : 3306, // For Windows or network connections + "UnixSocket" : "/var/run/mysqld/mysqld.sock", // For UNIX on localhost + "Database" : "orthanc", + "Username" : "orthanc", + "Password" : "orthanc", + "Lock" : true // See section about Locking + }, + "Plugins" : [ + "/home/user/orthanc-databases/BuildMySQL/libOrthancMySQLIndex.so", + "/home/user/orthanc-databases/BuildMySQL/libOrthancMySQLStorage.so" + ] + } + +**Important:** The ``EnableIndex`` and ``EnableStorage`` options must +be explicitly set to ``true``, otherwise Orthanc will continue to use +its default SQLite back-end and the filesystem storage area. + +**Remark:** When using the ``Storage`` MySQL plugin, the DICOM files +are stored as blobs in the database. This might actually consume more +space than the DICOM file itself. + +Note that a typical usage of the MySQL plugin is to enable only the +``Index``, using the default filesystem storage for DICOM files. + + + +.. highlight:: text + +Orthanc must of course be **restarted** after the modification of its +configuration file. The log will contain an output similar to:: + + $ ./Orthanc Configuration.json + W0710 14:25:35.143828 main.cpp:1298] Orthanc version: 1.3.2 + W0710 14:25:35.146528 OrthancInitialization.cpp:120] Reading the configuration from: "./Configuration.json" + [...] + W0710 14:25:35.173652 main.cpp:671] Loading plugin(s) from: /home/jodogne/Subversion/orthanc-databases/BuildMySQL/libOrthancMySQLIndex.so + W0710 14:25:35.175927 PluginsManager.cpp:269] Registering plugin 'mysql-index' (version mainline) + W0710 14:25:35.176213 PluginsManager.cpp:168] Performance warning: The database index plugin was compiled against an old version of the Orthanc SDK, consider upgrading + W0710 14:25:35.176323 main.cpp:671] Loading plugin(s) from: /home/jodogne/Subversion/orthanc-databases/BuildMySQL/libOrthancMySQLStorage.so + W0710 14:25:35.177172 PluginsManager.cpp:269] Registering plugin 'mysql-storage' (version mainline) + W0710 14:25:35.180684 PluginsManager.cpp:168] Your MySQL server cannot store DICOM files larger than 16MB + W0710 14:25:35.180714 PluginsManager.cpp:168] => Consider increasing "max_allowed_packet" in "my.cnf" if this limit is insufficient for your use + W0710 14:25:35.246150 main.cpp:1098] Using a custom database from plugins + W0710 14:25:35.246210 main.cpp:1109] Using a custom storage area from plugins + [...] + W0710 14:25:37.073633 main.cpp:683] Orthanc has started + + + +Advanced options +---------------- + +Several advanced options are available as well to fine-tune the +configuration of the MySQL plugins. They are documented below. + + +Locking +^^^^^^^ + +.. highlight:: json + +By default, the plugins lock the database (using `MySQL/MariaDB +"GET_LOCK()" +<https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_get-lock>`__) +to prevent other instances of Orthanc from using the same database. If +you want several instances of Orthanc to share the same database, set +the ``Lock`` option to ``false`` in the configuration file. + +Obviously, one must be very cautious when sharing the same database +between instances of Orthanc. In particular, all these instances +should share the same configuration.
--- a/Sphinx/source/plugins/postgresql.rst Fri Jun 22 10:54:20 2018 +0200 +++ b/Sphinx/source/plugins/postgresql.rst Tue Jul 10 14:45:40 2018 +0200 @@ -23,13 +23,13 @@ .. highlight:: text -The procedure to compile these plugins is similar of that for the +The procedure to compile these plugins is similar to that for the :ref:`core of Orthanc <compiling>`. The following commands should work -for every UNIX-like distribution (including GNU/Linux):: +for most UNIX-like distribution (including GNU/Linux):: - $ mkdir Build - $ cd Build - $ cmake .. -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release + $ mkdir BuildPostgreSQL + $ cd BuildPostgreSQL + $ cmake ../PostgreSQL -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release $ make The compilation will produce 2 shared libraries, each containing one plugin for Orthanc: @@ -58,10 +58,12 @@ Orthanc <compiling>` have already been installed):: $ sudo apt-get install libpq-dev postgresql-server-dev-all - $ cmake .. -DCMAKE_BUILD_TYPE=Release \ - -DALLOW_DOWNLOADS=ON \ - -DUSE_SYSTEM_GOOGLE_TEST=OFF \ - -DUSE_SYSTEM_ORTHANC_SDK=OFF + $ mkdir BuildPostgreSQL + $ cd BuildPostgreSQL + $ cmake ../PostgreSQL -DCMAKE_BUILD_TYPE=Release \ + -DALLOW_DOWNLOADS=ON \ + -DUSE_SYSTEM_GOOGLE_TEST=OFF \ + -DUSE_SYSTEM_ORTHANC_SDK=OFF $ make @@ -71,7 +73,7 @@ .. highlight:: json You of course first have to :ref:`install Orthanc <binaries>`, with a -version above 0.9.1. You then have to **create a database** dedicated +version above 0.9.5. You then have to **create a database** dedicated to Orthanc on some PostgreSQL server. Please refer to the `PostgreSQL documentation <https://www.postgresql.org/docs/current/static/tutorial-createdb.html>`__. @@ -86,7 +88,6 @@ { "Name" : "MyOrthanc", - [...] "PostgreSQL" : { "EnableIndex" : true, "EnableStorage" : true, @@ -97,18 +98,26 @@ "Password" : "orthanc" }, "Plugins" : [ - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLIndex.so", - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLStorage.so" + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" ] } -Note that ``EnableIndex`` and ``EnableStorage`` must be explicitly set -to true, otherwise Orthanc will continue to use its default SQLite -back-end. +**Important:** The ``EnableIndex`` and ``EnableStorage`` options must +be explicitly set to ``true``, otherwise Orthanc will continue to use +its default SQLite back-end and the filesystem storage area. -**Remark:** When using the ``Storage`` PostgreSQL plugin, the DICOM files are stored as large objects in the database. This might actually consume more space than the DICOM file itself. We have observed overhead up to 40%. However, it seems this overhead is temporary and comes from Write-Ahead Logging. Check this `discussion <https://groups.google.com/d/msg/orthanc-users/pPzHOpb--iw/QkKZ808gIgAJ>`__ on the Orthanc Users group for more info). +**Remark:** When using the ``Storage`` PostgreSQL plugin, the DICOM +files are stored as large objects in the database. This might +actually consume more space than the DICOM file itself. We have +observed overhead up to 40%. However, it seems this overhead is +temporary and comes from Write-Ahead Logging. Check this `discussion +<https://groups.google.com/d/msg/orthanc-users/pPzHOpb--iw/QkKZ808gIgAJ>`__ +on the Orthanc Users group for more info). -Note that a typical usage of the PostgreSQL plugin is to enable only the ``Index`` and continue using the default filesystem storage for DICOM files. +Note that a typical usage of the PostgreSQL plugin is to enable only +the ``Index``, and to use the default filesystem storage for DICOM +files. @@ -121,10 +130,10 @@ W0212 16:30:34.576972 11285 main.cpp:632] Orthanc version: 0.8.6 W0212 16:30:34.577386 11285 OrthancInitialization.cpp:80] Using the configuration from: Configuration.json [...] - W0212 16:30:34.598053 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/OrthancPostgreSQL/Build/libOrthancPostgreSQLIndex.so + W0212 16:30:34.598053 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so W0212 16:30:34.598470 11285 PluginsManager.cpp:258] Registering plugin 'postgresql-index' (version 1.0) W0212 16:30:34.598491 11285 PluginsManager.cpp:148] Using PostgreSQL index - W0212 16:30:34.608289 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/OrthancPostgreSQL/Build/libOrthancPostgreSQLStorage.so + W0212 16:30:34.608289 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so W0212 16:30:34.608916 11285 PluginsManager.cpp:258] Registering plugin 'postgresql-storage' (version 1.0) W0212 16:30:34.608947 11285 PluginsManager.cpp:148] Using PostgreSQL storage area [...] @@ -140,15 +149,14 @@ { "Name" : "MyOrthanc", - [...] "PostgreSQL" : { "EnableIndex" : true, "EnableStorage" : true, "ConnectionUri" : "postgresql://username:password@localhost:5432/database" }, "Plugins" : [ - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLIndex.so", - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLStorage.so" + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" ] } @@ -180,7 +188,6 @@ { "Name" : "MyOrthanc", - [...] "PostgreSQL" : { "EnableIndex" : true, "EnableStorage" : true, @@ -188,8 +195,8 @@ "ConnectionUri" : "postgresql://username:password@localhost:5432/database" }, "Plugins" : [ - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLIndex.so", - "/home/user/OrthancPostgreSQL/Build/libOrthancPostgreSQLStorage.so" + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", + "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" ] }
--- a/Sphinx/source/users/backup.rst Fri Jun 22 10:54:20 2018 +0200 +++ b/Sphinx/source/users/backup.rst Tue Jul 10 14:45:40 2018 +0200 @@ -38,16 +38,22 @@ necessary for Orthanc >= 0.7.3. -PostgreSQL ----------- +PostgreSQL and MySQL +-------------------- The default SQLite engine is well adapted for DICOM routing or for image buffering tasks, but not for enterprise scenarios. In such cases, you are highly recommended to use the `PostgreSQL back-end -<http://www.orthanc-server.com/static.php?page=postgresql>`__. +<http://www.orthanc-server.com/static.php?page=postgresql>`__ or the +`MySQL/MariaDB back-end +<http://www.orthanc-server.com/static.php?page=mysql>`__. If using PostgreSQL, you can do hot backups (i.e. while Orthanc is running), and you benefit from all the flexibility of PostgreSQL backup. These procedures are out of the scope of this manual. Please check the `official backup and restore manual <https://www.postgresql.org/docs/devel/static/backup.html>`__. + +Similar backup procedures are available for MySQL and MariaDB as +well. Please check the official manual about `database backup methods +<https://dev.mysql.com/doc/refman/8.0/en/backup-methods.html>`__.
--- a/Sphinx/source/users/replication.rst Fri Jun 22 10:54:20 2018 +0200 +++ b/Sphinx/source/users/replication.rst Tue Jul 10 14:45:40 2018 +0200 @@ -23,9 +23,9 @@ :ref:`configuration file <configuration>` in order to create a new database elsewhere on the filesystem (if using the default SQLite backend), or on the database management system (e.g. if using -:ref:`PostgreSQL <postgresql>`). This is important to let the user -experiment a new version of Orthanc, while keeping the older version -up and running. +:ref:`PostgreSQL <postgresql>` or :ref:`MySQL/MariaDB <mysql>`). This +is important to let the user experiment a new version of Orthanc, +while keeping the older version up and running. If you decide to upgrade the database schema, you have to apply the following 3 steps: @@ -85,7 +85,9 @@ * The source Orthanc uses the default SQLite back-end of Orthanc (and not the `PostgreSQL plugin - <http://www.orthanc-server.com/static.php?page=postgresql>`_, for + <http://www.orthanc-server.com/static.php?page=postgresql>`_ or the + `MySQL/MariaDB plugin + <http://www.orthanc-server.com/static.php?page=mysql>`_, for instance), * You have command-line access to the source Orthanc, and * The transparent :ref:`compression` of the DICOM instances is