Installing PostgreSQL Database¶
- Log in to the server that will host the database, and open a terminal window.
- Download the PostgreSQL 9.4 Yum repository.
wget https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-3.noarch.rpm
- Install the Yum repository from the file that you downloaded.
sudo yum localinstall pgdg-redhat94-9.4-3.noarch.rpm
- Install PostgreSQL.
sudo yum install postgresql94-server postgresql94-contrib
- Initialize the database.
sudo service postgresql-9.4 initdb
- Set PostgreSQL to start on boot.
sudo chkconfig postgresql-9.4 on
- Start the PostgreSQL server.
sudo service postgresql-9.4 start
- Switch to the postgres Linux user account that was created during the installation.
sudo --login --user postgres
- Start the PostgreSQL interactive terminal.
psql
- Create the Mattermost database.
postgres=# CREATE DATABASE mattermost;
- Create the Mattermost user ‘mmuser’.
postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';
Note
Use a password that is more secure than ‘mmuser-password’.
- Grant the user access to the Mattermost database.
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
- Exit the PostgreSQL interactive terminal.
postgres=# \q
- Log out of the postgres account.
exit
- Allow Postgres to listen on all assigned IP Addresses.
- Open
/etc/postgresql/9.4/main/postgresql.conf
as root in a text editor.- Find the following line:
#listen_addresses = 'localhost'
- Uncomment the line and change
localhost
to*
:listen_addresses = '*'
- Restart PostgreSQL for the change to take effect:
sudo service postgresql-9.4 restart
- Modify the file
pg_hba.conf
to allow the Mattermost server to communicate with the database.
If the Mattermost server and the database are on the same machine:
- Open
/var/lib/pgsql/9.4/data/pg_hba.conf
as root in a text editor.- Find the following line:
local all all peer
- Change
peer
totrust
:local all all trust
If the Mattermost server and the database are on different machines:
- Open
/var/lib/pgsql/9.4/data/pg_hba.conf
as root in a text editor.- Add the following line to the end of the file, where {mattermost-server-IP} is the IP address of the machine that contains the Mattermost server.
host all all {mattermost-server-IP}/32 md5
- Reload PostgreSQL:
sudo service postgresql-9.4 reload
- Verify that you can connect with the user mmuser.
- If the Mattermost server and the database are on the same machine, use the following command:
psql --dbname=mattermost --username=mmuser --password
- If the Mattermost server is on a different machine, log into that machine and use the following command:
psql --host={postgres-server-IP} --dbname=mattermost --username=mmuser --password
Note
You might have to install the PostgreSQL client software to use the command.
The PostgreSQL interactive terminal starts. To exit the PostgreSQL interactive terminal, type
\q
and press Enter.
With the database installed and the initial setup complete, you can now install the Mattermost server.