For CentOS
The commands to configure Postgres database are different for CentOS, Debian, and Ubuntu. Refer to the respective section to view the procedure for your platform.
-
Install the supported version of Postgres using the following commands:
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum install postgresql96-contrib postgresql96-server
For more information about the supported version of Postgres, see the DAS Support Matrix. -
Initialize the Postgres database by running the following command:
/usr/pgsql-9.6/bin/postgresql96-setup initdb
-
Open the
pg_hba.conf
file for editing by entering the following command:vi /var/lib/pgsql/9.6/data/pg_hba.conf
-
Add lines similar to the following lines:
local all <dbuser> md5 host all <dbuser> 0.0.0.0/0 md5 host all <dbuser> ::/0 md5 local all postgres ident
-
Open the
postgresql.conf
file for editing.vi /var/lib/pgsql/9.6/data/postgresql.conf
-
Add, update, or uncomment the
listen_addresses
line as follows:listen_addresses = '*'
-
Start the Postgres database by running the following command:
service postgresql-9.6 start
Wait for the command to finish in some time or kill the command if it does not respond.
-
Create roles in Postgres by running the following commands as a Postgres
user:
psql -tc "SELECT 1 FROM pg_database WHERE datname = <dbname>" | grep 1 || ( psql -c "CREATE ROLE <dbuser> WITH LOGIN PASSWORD <dbpass>;" && psql -c "ALTER ROLE <dbuser> CREATEDB;" && psql -c "CREATE DATABASE <dbname>;" && psql -c "GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <dbuser>;")
Replace
<dbname>
with the database name,<dbuser>
with the database username and<dbpass>
with the database password.