PostgreSQL

From belajarwiki
Revision as of 09:45, 7 January 2022 by Aditya (talk | contribs)
Jump to navigation Jump to search

Install PostgreSQL di Ubuntu 20.04.01

  sudo apt update
  sudo apt install postgresql postgresql-contrib


Cara akses PostgreSQL

Jika kita mempunyai database dengan nama psql

Cara 1

  sudo -i -u postgres
  psql 

Cara 2

  sudo -u postgres psql


Perintah PostgreSQL

Membuat user

  sudo -u postgres createuser --interactive

Membuat database

  sudo -u postgres createdb <namadb>

atau

  sudo -i -u postgres
  psql 
  create database <namadb>

Cek database

  \list

Pilih database

  \connect <namadb>


Untuk di server

Selain setting security groups di server, setting juga di etc/postgresql/<version>/main/pg_hba.conf

host     all     all     127.0.0.1/32     md5
host     all     all     10.0.1.0/24     md5

Dan di etc/postgresql/<version>/main/postgresql.conf Edit postgresql.conf and change listen_address:

listen_addresses='*'