Configure the database

First we will create the nextcloud user:

_$: sudo su - postgres
postgres_$: createuser -P nextcloud
Enter password for new role: <password>
Enter it again: <password>

And then the nextcloud database. The database owner will be the nextcloud user:

postgres_$: createdb --owner=nextcloud nextcloud

Let us check everything is all right:

postgres_$: psql
psql (9.4.5)

postgres=# \pset pager off
Pager usage is off.

postgres=# \x auto
Expanded display is used automatically.

postgres=# \l
List of databases
-[ RECORD 1 ]-----+----------------------
Name              | nextcloud
Owner             | nextcloud
Encoding          | UTF8
Collate           | en_GB.UTF-8
Ctype             | en_GB.UTF-8
Access privileges |

postgres=# \q