[[postgresDB2]]
= PostgreSQL Database Use
:author: Artur Hefczyc <artur.hefczyc@tigase.net>
:version: v2.1, June 2017: Reformatted for v8.0.0.

This guide describes how to configure Tigase server to use link:http://www.postgresql.org/[PostgreSQL] database as a user repository.

If you used an XML based user repository before you can copy all user data to PostgreSQL database using repository management tool. All steps are described below.

== PostgreSQL Database Preparation
Create new database user account which will be used to connect to your database:

[source,sh]
-----
# createuser
Enter name of user to add: tigase
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) y
-----

Now using new database user account create database for your service:

[source,sh]
-----
# createdb -U tigase tigasedb
CREATE DATABASE
-----

Now you can load the database schema:

[source,sh]
-----
# psql -U tigase -d tigasedb -f postgresql-schema.sql
-----

Now the database is ready for Tigase server to use.

== Server Configuration
Server configuration is almost identical to MySQL database setup. The only difference is the connection string which usually looks like:

[source,dsl]
-----
dataSource {
    default () {
        uri = 'postgresql://localhost/tigasdb?user=tigase'
    }
}
-----
