Skip to main content
Skip table of contents

Step 4 of 8 Configure PostgreSQL for XNAT


XNAT uses the PostgreSQL database to store all of its persistent data that's not stored in files on the local storage device. In this step, you'll configure your local database so that XNAT can access it for data storage. 


The basic configuration for PostgreSQL is very simple:

  • Create an XNAT database user
  • Create an empty XNAT database

Create an XNAT database user

The PostgreSQL equivalent of root or sudo access is becoming the postgres user. To create a new user, you can use sudo to act as the postgres user. Once you've done that, you can create your new user:

vagrant@xnat-11:~$ sudo su - postgres
postgres@xnat-11:~$ createuser -d xnat
postgres@xnat-11:~$ exit

Create an empty XNAT database

The -d option in previous command specifies that the newly created user has the ability to create new databases. This makes it easier to create new database instances later on when you're working with a development machine where you may want to try various configurations. Now you can quit as the postgres user and become the user you created a couple steps ago. The interesting thing here is that, when you run commands that affect the database from the command line, the name of the user performing those operations is assumed to be the same as your current username and the database used is the database with the same name. That means that, if you named your new user xnat and your new database user xnat, all database commands will be done with the xnat database user's permissions, including in this instance the ability to create a new database, which will by default also be named xnat:

vagrant@xnat-11:~$ sudo su - xnat
xnat@xnat-11:~$ createdb
xnat@xnat-11:~$ psql
psql (9.5.3)
Type "help" for help.
xnat=> \password
Enter new password:
Enter it again:
xnat=> \q

This creates a new database with the default name (xnat) owned by the default user (xnat). psql is the PostgreSQL command-line client and, when you launch it without any parameters, it logins you in as the default user to the default database. The command \password lets you set the password for the current user. You can quit psql by typing \q then hitting Enter.

Make a note of the value you use when setting the password for your xnat database user. You'll use that value later on when configuring XNAT's database connection. For ease of use, you can just enter the password as xnat as well.

There are many tools that you can use to access the database, including Web-based and application clients. Tools that run remotely, such as pgAdmin3, usually require more configuration. The documentation for pgAdmin3 describes how to set this up properly.


You've created a database user and schema that XNAT can use to store its persistent data. This will be used as part of the XNAT service configuration in a later step.

Go to the next step

Installing XNAT

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.