Skip to main content
  1. Posts/

How to Install PostgreSQL

·2 mins·
postgresql postgresql linux
Table of Contents

PostgreSQL merupakan object-relational database management system (ORDBMS) based on POSTGRES, Version 4.2 yang dikembangkan oleh Universitas California di Departemen Ilmu Komputer Berkeley.

PostgreSQL bersifat open source dengan beberapa fitur penting meliputi:

  • complex queries
  • foreign keys
  • triggers
  • updatable views
  • transactional integrity
  • multiversion concurrency control

Install PostgreSQL
#

Install postgresql melalui repo resmi dan tentukan OS yang Anda pakai melalui PostgreSQL: Downloads

Contoh skrip untuk install postgresql dengan di Rocky Linux

dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql15.x86_64 postgresql15-server.x86_64 postgresql15-docs.x86_64 postgresql15-contrib.x86_64

Inisialisasi Database
#

Inisialisai database atau buat baru cluster database PostgreSQL menggunakan

/usr/pgsql-15/bin/postgresql-15-setup initdb

Selanjutnya enable dan start service PostgreSQL

systemctl enable --now postgresql-15

Sampai ini Anda sudah dapat me-remote PostgreSQL.

su - postgres -c psql

Client Authentication
#

Jika menemukan error seperti berikut.

# psql -U postgres
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres"

Anda perlu mengedit file pg_hba.conf lalu ubah authentication dari peer menjadi md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     md5
local   all             postgres                                trust
  • Peer Authentication: metode otentikasi default untuk koneksi lokal berdasarkan UNIX user. metode ini mengizinkan akses login tanpa kata sandi tambahan.
  • MD5 Authentication: metode otentikasi ini akan selalu meminta password yang di-hash dalam format MD5 untuk memverifikasi identitas.
  • Trust Authentication: metode otentikasi yang tidak aman karena tidak memerlukan otentikasi apa pun. Gunakan metode ini ketika Anda ingin mengubah password user postgres.

Restart service postgresql

systemctl restart postgresql-15

Selanjutnya ubah password user postgres

psql -U postgres
ALTER USER postgres with password ‘new-password’;

Lalu edit kembali file pg_hba.conf dan ubah authentication trust menjadi md5.

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     md5
local   all             postgres                                md5

Buat file .pgpass untuk menyimpan password sehingga menjadi autologin tanpa perlu memasukan password.

touch ~/.pgpass
chmod 600 ~/.pgpass
nano ~/.pgpass
# hostname:port:database:username:password
*:*:*:postgres:new-password

Test akses login postgresql dengan user postgres.

psql -U postgres

Related

Mengatasi Masalah Interface Ethernet Tidak Terdeteksi
·1 min
linux linux
Error Display_Server_Not_Supported di AnyDesk
·1 min
linux linux
Error 'Key is stored in legacy trusted.gpg keyring' di Ubuntu
·2 mins
ubuntu linux ubuntu
Install Nginx dengan PHP-FPM dan Userdir
·9 mins
nginx centos linux php nginx
Eksekusi Skrip Saat Startup dan Shutdown
·2 mins
linux linux
Create Multiple IP Addresses in Linux
·2 mins
linux centos ubuntu linux