Cara Install Postgres di CentOS 7

Pastikan CentOS update

sudo yum update

Install Postgres

sudo yum install postgresql-server postgresql-contrib

Inisiasi Server Postgres

sudo postgresql-setup initdb

Initializing database … OK

Setting koneksi eksternal

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

tambahkan line berikut diakhir file:

host    all             all                  md5
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all               ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres            ident
#host    replication     postgres        ::1/128                 ident

Edit postgresql.conf

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

cari line berikut:

59 #listen_addresses = 'localhost'         # what IP address(es) to listen on;

uncomment dan ganti localhost menjadi *

listen_addresses = '*'         # what IP address(es) to listen on;

start postgresql

sudo systemctl start postgresql
sudo systemctl enable postgresql

setting password db

sudo -i -u postgres

sudo -i -u postgres
-bash-4.2$ psql
psql (9.2.24)
Type "help" for help.

postgres=# \password
Enter new password:
Enter it again:

restart postgresql

sudo service postgresql restart

Leave a Reply