Install PostgreSQL on CentOS7



if you want install latest version check official site

I will install postgres9.6 for CentOS7.

default version of postgres in CentOS7 rpm is not recommanded, I need some new features in postgres9.5+.

sudo yum install
sudo yum install postgresql96-server postgresql96-contrib

# initialize the database
sudo postgresql96-setup initdb

Config for remote access

Set listen port to wildcard

# sudo vim /var/lib/pgsql/9.6/data/postgresql.conf
listen_addresses = '*'

Change HBA (host-based authentication) configuration

# sudo vim /var/lib/pgsql/9.6/data/pg_hba.conf
host    all             all               md5

Start server

sudo systemctl enable postgresql-9.6
sudo systemctl start postgresql-9.6

# check listen port
ss -ant | grep 5432

Login default role

sudo -i -u postgres
# to access PostgreSQL prompt
# for quit PostgreSQL prompt

Create a new role

createuser --interactive

My new role is rwuser

Create a new database

createdb test1

Login new role

# access PostgreSQL prompt with new role
sudo su -c "psql -d test1" - rwuser
# type following command in  PostgreSQL prompt
# then set your new password

You can use navicat to connect pgsql later.