Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/postgresql.rst @ 361:84e3a2612c36
links to hg
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Mar 2020 20:37:49 +0200 |
parents | 011b01ccf52d |
children | 0fb9369e893e |
rev | line source |
---|---|
24 | 1 .. _postgresql: |
2 | |
3 | |
4 PostgreSQL plugins | |
5 ================== | |
6 | |
27 | 7 .. contents:: |
8 | |
9 The Orthanc project provides two **official** plugins to replace the | |
10 default storage area (on the filesystem) and the default SQLite index | |
11 by a PostgreSQL database. | |
12 | |
13 For general information, check out the `official homepage of the | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
14 plugins <https://www.orthanc-server.com/static.php?page=postgresql>`__. |
27 | 15 |
16 | |
17 | |
18 Compilation | |
19 ----------- | |
20 | |
128 | 21 Static linking |
22 ^^^^^^^^^^^^^^ | |
23 | |
27 | 24 .. highlight:: text |
25 | |
154 | 26 The procedure to compile these plugins is similar to that for the |
27 | 27 :ref:`core of Orthanc <compiling>`. The following commands should work |
154 | 28 for most UNIX-like distribution (including GNU/Linux):: |
27 | 29 |
154 | 30 $ mkdir BuildPostgreSQL |
31 $ cd BuildPostgreSQL | |
32 $ cmake ../PostgreSQL -DSTATIC_BUILD=ON -DCMAKE_BUILD_TYPE=Release | |
27 | 33 $ make |
34 | |
35 The compilation will produce 2 shared libraries, each containing one plugin for Orthanc: | |
36 | |
37 * ``OrthancPostgreSQLIndex`` replaces the default SQLite index of Orthanc by PostgreSQL. | |
38 * ``OrthancPostgreSQLStorage`` makes Orthanc store the DICOM files it receives into PostgreSQL. | |
39 | |
128 | 40 |
41 Microsoft Windows and Apple OS X | |
42 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
43 | |
28 | 44 Pre-compiled binaries for Microsoft Windows `are also available |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
45 <https://www.orthanc-server.com/browse.php?path=/plugin-postgresql>`__. |
30 | 46 A package for `Apple's Mac OS X |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
47 <https://www.osimis.io/en/download.html>`__ |
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
48 is available courtesy of `Osimis <https://www.osimis.io/>`__. |
27 | 49 |
50 | |
263
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
51 .. _postgresql-ubuntu1604: |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
52 |
128 | 53 Dynamic linking on Ubuntu 16.04 |
54 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
55 | |
56 .. highlight:: text | |
57 | |
58 If static linking is not desired, here are build instructions for | |
59 Ubuntu 16.04 (provided build dependencies for the :ref:`core of | |
60 Orthanc <compiling>` have already been installed):: | |
61 | |
62 $ sudo apt-get install libpq-dev postgresql-server-dev-all | |
154 | 63 $ mkdir BuildPostgreSQL |
64 $ cd BuildPostgreSQL | |
65 $ cmake ../PostgreSQL -DCMAKE_BUILD_TYPE=Release \ | |
66 -DALLOW_DOWNLOADS=ON \ | |
67 -DUSE_SYSTEM_GOOGLE_TEST=OFF \ | |
68 -DUSE_SYSTEM_ORTHANC_SDK=OFF | |
128 | 69 $ make |
70 | |
263
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
71 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
72 .. _postgresql-cmake: |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
73 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
74 Dynamic linking on other GNU/Linux distributions |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
75 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
76 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
77 .. highlight:: text |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
78 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
79 The build instructions should always be very similar to those for |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
80 :ref:`Ubuntu 16.04 <postgresql-ubuntu1604>`. One difficulty that could |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
81 however arise is that it is possible that the CMake environment that |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
82 is shipped with the GNU/Linux distribution cannot locate a recent |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
83 version of the development headers for PostgreSQL. This leads to an |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
84 error while invoking CMake that looks like:: |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
85 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
86 -- Could NOT find PostgreSQL (missing: PostgreSQL_TYPE_INCLUDE_DIR) |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
87 |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
88 In such a situation, please add your version of PostgreSQL to the |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
89 macro ``PostgreSQL_ADDITIONAL_VERSIONS`` that is defined at the end of |
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
90 the `Resources/CMake/PostgreSQLConfiguration.cmake file |
361 | 91 <https://hg.orthanc-server.com/orthanc-databases/file/tip/Resources/CMake/PostgreSQLConfiguration.cmake>`__ |
92 in the sources of the project. | |
263
39609c9a2c41
note about includes for postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
93 |
128 | 94 |
27 | 95 Usage |
96 ----- | |
97 | |
98 .. highlight:: json | |
99 | |
31
93bbfaf0e62c
worklist instructions migrated to a specific page, indexing of Osimis Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
30
diff
changeset
|
100 You of course first have to :ref:`install Orthanc <binaries>`, with a |
154 | 101 version above 0.9.5. You then have to **create a database** dedicated |
28 | 102 to Orthanc on some PostgreSQL server. Please refer to the `PostgreSQL |
103 documentation | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
104 <https://www.postgresql.org/docs/current/tutorial-createdb.html>`__. |
27 | 105 |
106 Once Orthanc is installed and the database is created, you must add a | |
107 section in the :ref:`configuration file <configuration>` that | |
108 specifies the address of the **PostgreSQL server together with your | |
109 credentials**. You also have to tell Orthanc in which path it can find | |
110 the plugins: This is done by properly modifying the ``Plugins`` | |
111 option. You could for instance adapt the following configuration | |
112 file:: | |
113 | |
114 { | |
115 "Name" : "MyOrthanc", | |
116 "PostgreSQL" : { | |
117 "EnableIndex" : true, | |
118 "EnableStorage" : true, | |
119 "Host" : "localhost", | |
120 "Port" : 5432, | |
121 "Database" : "orthanc", | |
122 "Username" : "orthanc", | |
181 | 123 "Password" : "orthanc", |
124 "EnableSsl" : false // New in version 3.0 | |
27 | 125 }, |
126 "Plugins" : [ | |
154 | 127 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", |
128 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" | |
27 | 129 ] |
130 } | |
131 | |
154 | 132 **Important:** The ``EnableIndex`` and ``EnableStorage`` options must |
133 be explicitly set to ``true``, otherwise Orthanc will continue to use | |
134 its default SQLite back-end and the filesystem storage area. | |
27 | 135 |
181 | 136 **Remark 1:** When using the ``Storage`` PostgreSQL plugin, the DICOM |
154 | 137 files are stored as large objects in the database. This might |
138 actually consume more space than the DICOM file itself. We have | |
139 observed overhead up to 40%. However, it seems this overhead is | |
140 temporary and comes from Write-Ahead Logging. Check this `discussion | |
141 <https://groups.google.com/d/msg/orthanc-users/pPzHOpb--iw/QkKZ808gIgAJ>`__ | |
142 on the Orthanc Users group for more info). | |
118 | 143 |
181 | 144 **Remark 2:** A typical usage of the PostgreSQL plugin is to enable |
145 only the ``Index``, and to use the default filesystem storage for | |
146 DICOM files (on a NAS with proper disaster recovery strategies). This | |
147 setup provides best performance for large-scale databases. | |
148 | |
149 **Remark 3:** Setting the ``EnableSsl`` to ``true`` forces the use of | |
150 `SSL connections | |
151 <https://www.postgresql.org/docs/current/libpq-ssl.html>`__ between | |
152 Orthanc and the PostgreSQL server. It is a synonym for | |
153 ``sslmode=require`` in connections URI (see below). Setting | |
154 ``EnableSsl`` to ``false`` corresponds to ``sslmode=disable`` | |
155 (i.e. SSL is not used, even if it is both available in Orthanc and | |
156 PostgreSQL). To choose other values for the SSL mode (i.e. ``allow`` | |
157 and ``prefer``), please use connection URIs. | |
118 | 158 |
159 | |
94
b0a71b880ca0
fix link + remark about disk usage overhead
Alain Mazy <alain@mazy.be>
parents:
81
diff
changeset
|
160 |
27 | 161 .. highlight:: text |
162 | |
163 Orthanc must of course be **restarted** after the modification of its | |
164 configuration file. The log will contain an output similar to:: | |
165 | |
166 $ ./Orthanc Configuration.json | |
167 W0212 16:30:34.576972 11285 main.cpp:632] Orthanc version: 0.8.6 | |
168 W0212 16:30:34.577386 11285 OrthancInitialization.cpp:80] Using the configuration from: Configuration.json | |
169 [...] | |
154 | 170 W0212 16:30:34.598053 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so |
27 | 171 W0212 16:30:34.598470 11285 PluginsManager.cpp:258] Registering plugin 'postgresql-index' (version 1.0) |
172 W0212 16:30:34.598491 11285 PluginsManager.cpp:148] Using PostgreSQL index | |
154 | 173 W0212 16:30:34.608289 11285 main.cpp:379] Registering a plugin from: /home/jodogne/Subversion/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so |
27 | 174 W0212 16:30:34.608916 11285 PluginsManager.cpp:258] Registering plugin 'postgresql-storage' (version 1.0) |
175 W0212 16:30:34.608947 11285 PluginsManager.cpp:148] Using PostgreSQL storage area | |
176 [...] | |
177 W0212 16:30:34.674648 11285 main.cpp:530] Orthanc has started | |
178 | |
179 | |
180 .. highlight:: json | |
181 | |
182 Instead of specifying explicit authentication parameters, you can also | |
183 use the `PostgreSQL connection URIs syntax | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
184 <https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING>`__. For |
27 | 185 instance:: |
186 | |
187 { | |
188 "Name" : "MyOrthanc", | |
189 "PostgreSQL" : { | |
190 "EnableIndex" : true, | |
191 "EnableStorage" : true, | |
181 | 192 "ConnectionUri" : "postgresql://username:password@localhost:5432/database?sslmode=prefer" |
27 | 193 }, |
194 "Plugins" : [ | |
154 | 195 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", |
196 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" | |
27 | 197 ] |
198 } | |
199 | |
200 | |
201 **Remark:** The Debian Med project maintains `another useful set of | |
202 instructions | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
203 <https://salsa.debian.org/med-team/orthanc-postgresql/-/blob/master/debian/README.Debian>`__. |
27 | 204 |
205 | |
206 Advanced options | |
207 ---------------- | |
208 | |
209 Several advanced options are available as well to fine-tune the | |
210 configuration of the PostgreSQL plugins. They are documented below. | |
211 | |
212 | |
270
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
213 .. _postgresql-lock: |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
214 |
27 | 215 Locking |
216 ^^^^^^^ | |
217 | |
218 .. highlight:: json | |
219 | |
220 By default, the plugins lock the database (using `PostgreSQL advisory | |
221 locks | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
222 <https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS>`__) |
27 | 223 to prevent other instances of Orthanc from using the same PostgreSQL |
224 database. If you want several instances of Orthanc to share the same | |
225 database, set the ``Lock`` option to ``false`` in the configuration | |
226 file:: | |
227 | |
228 { | |
229 "Name" : "MyOrthanc", | |
230 "PostgreSQL" : { | |
231 "EnableIndex" : true, | |
232 "EnableStorage" : true, | |
233 "Lock" : false, | |
234 "ConnectionUri" : "postgresql://username:password@localhost:5432/database" | |
235 }, | |
236 "Plugins" : [ | |
154 | 237 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLIndex.so", |
238 "/home/user/orthanc-databases/BuildPostgreSQL/libOrthancPostgreSQLStorage.so" | |
27 | 239 ] |
240 } | |
241 | |
242 Obviously, one must be very cautious when sharing the same database | |
243 between instances of Orthanc. In particular, all these instances | |
244 should share the same configuration. | |
245 | |
270
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
246 Furthermore, the core of Orthanc does not currently support the replay |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
247 of database transactions, which is necessary to deal with conflicts |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
248 between several instances of Orthanc that would simultaneously write |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
249 to the database. |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
250 |
336 | 251 As a consequence, as of Orthanc 1.6.0, when connecting multiple |
270
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
252 Orthanc to a single database by setting ``Lock`` to ``false``, there |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
253 should only be one instance of Orthanc acting as a writer and all the |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
254 other instances of Orthanc acting as readers only. Be careful to set |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
255 the option ``SaveJobs`` to ``false`` in the configuration file of all |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
256 the instances of Orthanc acting as readers. |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
257 |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
258 A refactoring is needed to improve the core of Orthanc in that |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
259 respect, for which we are looking for funding/donation from the |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
260 industry. Some issues reported in our bug tracker call for this |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
261 refactoring: `issue 83 |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
262 <https://bitbucket.org/sjodogne/orthanc/issues/83/>`__, `issue 121 |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
263 <https://bitbucket.org/sjodogne/orthanc/issues/121/>`__, `issue 151 |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
264 <https://bitbucket.org/sjodogne/orthanc/issues/151/>`__. |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
265 |
f29d75bc5c25
more info about database locking
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
266 |
27 | 267 |
268 Keep-alive | |
269 ^^^^^^^^^^ | |
270 | |
271 .. highlight:: text | |
272 | |
273 After some period of inactivity (users have reported 10 hours), you | |
274 might `experience an error | |
275 <https://bitbucket.org/sjodogne/orthanc/issues/15/postgresql-exceptions-after-time>`__ | |
276 such as:: | |
277 | |
278 E0220 03:20:51.562601 PluginsManager.cpp:163] Exception in database back-end: Error in PostgreSQL: server closed the connection unexpectedly. | |
279 This probably means the server terminated abnormally before or while processing the request. | |
280 E0220 06:51:03.924868 PluginsManager.cpp:163] Exception in database back-end: Error in PostgreSQL: no connection to the server | |
281 | |
282 This is due to a timeout in the PostgreSQL server. Please make sure to | |
283 `enable keep-alive | |
358
011b01ccf52d
fixing external hyperlinks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
284 <https://dba.stackexchange.com/questions/97534/is-there-a-timeout-option-for-remote-access-to-postgresql-database>`__ |
27 | 285 in the configuration of your PostgreSQL server |