General
=======

Orthanc PostgreSQL is a set of 2 plugins to Orthanc, a lightweight,
RESTful Vendor Neutral Archive for medical imaging. These plugins
override the default SQLite engine of Orthanc with a PostgreSQL
back-end. They bring scalability to Orthanc, making it
enterprise-ready.

Homepage: http://www.orthanc-server.com/static.php?page=postgresql


Configuration
=============

To enable the plugin, you must specify the parameters of your
PostgreSQL database by adapting the configuration file
"/etc/orthanc/postgresql.json". Then, restart the Orthanc service:

	$> sudo systemctl restart orthanc.service


Step-by-step tutorial
=====================

(1) Install the database server:

	$> sudo apt-get install postgresql


(2) Create a database account a database to store the
    content of Orthanc:

	$> sudo -u postgres createuser -e orthanc
	$> sudo -u postgres createdb -e -E utf8 -O orthanc orthanc_db


(3) Restrict access to the Orthanc database:

	Edit /etc/postgresql/VERSION/main/pg_hba.conf to contain

		local   orthanc_db     orthanc                                  ident

	somewhere AFTER the lines

		# Database administrative login by Unix domain socket
		local   all             postgres                                ident

	Reload PostgreSQL configuration

		$> sudo systemctl reload postgresql.service


(3) Edit the configuration file "/etc/orthanc/postgresql.json"
    to make Orthanc connect to PostgreSQL:

	"PostgreSQL" : {
		"EnableIndex" : true,
		"EnableStorage": true,
		"ConnectionUri" : "postgresql:///orthanc_db?user=orthanc",
	}

	Make sure to comment out all individual authentication
	parameters such as Host, Port, ...


(4) Restart the Orthanc service and check the logs:

	$> sudo apt-get install postgresql
	$> sudo less /var/log/orthanc/Orthanc.WARNING
	$> sudo less /var/log/postgresql/postgresl-VERSION-main.log


Further notes
=============

Setup

One can use any name for the database, as long as reality and
configuration match.

The database account should be "orthanc" in order to enable intuitive use
of PEER authentication because Orthanc is running as the "orthanc" system
user. If you need to use another database account adjust pg_hba.conf
accordingly or use a user name mapping (see PostgreSQL documentation).


Data integrity

If you intend to set "StoreMD5ForAttachments" to "true" in orthanc.json
you should strongly consider making sure the PostgreSQL cluster is set to
provide on-disk data page checksumming instead. Check with the following
SQL query:

	psql> select * from pg_settings where name = 'data_checksums';

There is no need to make Orthanc calculate MD5 sums when PostgreSQL is
already doing it for on-disk storage.


Data compression

Also, strongly consider to NOT set "StorageCompression" to "true" when
using PostgreSQL because the database will already compress data (TOAST,
EXTENDED storage, pg_largeobject)


Data migration
