To use PostgreSQL as your database. Install it with the following command:

[root@mattermost ~] yum -y install postgresql-server postgresql-contrib

After installation we have to init the database.

[root@mattermost ~] postgresql-setup initdb
Initializing database … OK

Then start PostgreSQL and enable it for automatic start.

[root@mattermost ~]# systemctl start postgresql
[root@mattermost ~]# systemctl enable postgresql
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.

Please verify, that PostgreSQL is running by executing.

[root@mattermost ~]# systemctl status postgresql

It should report something similar to this (make sure there is Active: active (running) somewhere in the text).

? postgresql.service – PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2016-03-04 11:37:50 CET; 44s ago
Main PID: 17660 (postgres)
CGroup: /system.slice/postgresql.service
??17660 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
??17661 postgres: logger process
??17663 postgres: checkpointer process
??17664 postgres: writer process
??17665 postgres: wal writer process
??17666 postgres: autovacuum launcher process
??17667 postgres: stats collector process

Mar 04 11:37:48 mattermost systemd[1]: Starting PostgreSQL database server…
Mar 04 11:37:50 mattermost systemd[1]: Started PostgreSQL database server.
Mar 04 11:37:59 mattermost systemd[1]: Started PostgreSQL database server.

Create mattermost database and database user

PostgreSQL automatically created a user and group with the name postgres. We use the user postgres to connect to the database engine and setup a database and a user that can access it.

Start a prompt as the user postgres:

[root@mattermost ~]# sudo -i -u postgres

Your prompt will now change to:

-bash-4.2$

Now let’s connect to the database server.

-bash-4.2$ psql
psql (9.2.15)
Type “help” for help.
postgres=#

Within the PostgreSQL prompt we now create a database with name ‘mattermost’.

postgres=# CREATE DATABASE mattermost;
CREATE DATABASE

Now we create a user ‘mmuser‘ with the password ‘DBAss47slX3′.

postgres=# CREATE USER mmuser WITH PASSWORD ‘DBAss47slX3‘;
CREATE ROLE

Grant the user access to the Mattermost database by typing:

postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
GRANT
postgres=#

We can then exit the PostgreSQL prompt by typing:

postgres=# \q
-bash-4.2$

And then exit the shell we started as user ‘postgres‘ with.

-bash-4.2$ exit
logout
[root@mattermost ~]#

Allow access to the PostgreSQL database from localhost via username/password

Later, our mattermost instance would like to talk to the PostgreSQL database and authenticate with username and password. To allow this, we slightly need to change the PostgreSQL configuration. Open the file:

vi /var/lib/pgsql/data/pg_hba.conf

with an editor like vi or nano and change the line:

host    all             all             127.0.0.1/32            ident

to:

host    all             all             127.0.0.1/32            md5

Save the file and then restart Postgresql.

[root@mattermost ~]# systemctl restart postgresql

We should verify that we did that correctly by connecting to the database server with our previously created user and password (use your password if you used a different one on your server):

[root@mattermost ~]# psql –host=127.0.0.1 –dbname=mattermost –username=mmuser –password
Password for user mmuser:
psql (9.2.15)
Type “help” for help.

mattermost=> \q
[root@mattermost ~]#

Leave a Reply

Your email address will not be published. Required fields are marked *