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             0.0.0.0/0               md5
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            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        127.0.0.1/32            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
psql
\password
Minum123$
\q
exit

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

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

restart postgresql

sudo service postgresql restart

Leave a Reply