Digital Ocean
- Buat Droplet
- Koneksi ke Droplet
sudo apt update
apt install postgresql postgresql-contrib
update-rc.d postgresql enable
service postgresql start
service postgresql status
Output:
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2022-10-18 10:09:53 UTC; 2min 7s ago
Main PID: 4320 (code=exited, status=0/SUCCESS)
CPU: 1ms
cd ../etc/postgresql
ls
cd 14/main/
ls
Output:
conf.d environment pg_ctl.conf pg_hba.conf pg_ident.conf postgresql.conf start.conf
ls -la
Output:
drwxr-xr-x 3 postgres postgres 4096 Oct 18 10:09 .
drwxr-xr-x 3 postgres postgres 4096 Oct 18 10:09 ..
drwxr-xr-x 2 postgres postgres 4096 Oct 18 10:09 conf.d
-rw-r--r-- 1 postgres postgres 315 Oct 18 10:09 environment
-rw-r--r-- 1 postgres postgres 143 Oct 18 10:09 pg_ctl.conf
-rw-r----- 1 postgres postgres 5002 Oct 18 10:09 pg_hba.conf
-rw-r----- 1 postgres postgres 1636 Oct 18 10:09 pg_ident.conf
-rw-r--r-- 1 postgres postgres 29032 Oct 18 10:09 postgresql.conf
-rw-r--r-- 1 postgres postgres 317 Oct 18 10:09 start.conf
sudo nano pg_hba.conf
Kemudian masukan pada baris paling akhir:
host all all 0.0.0.0/0 trust
host all all ::/0 trust
sudo nano postgresql.conf
Edit baris ini, hilangkan komentar:
listen_addresses = '*' # what IP address(es) to listen on;
service postgresql restart
Koneksi dengan PgAdmin4
- Buka PgAdmin4, lalu di bagian menu kiri klik kanan Create Server
- Pada Tab General masukan nama koneksi
- Pada Tab Connection, masukan Host dengan IP dari Droplet DigitalOcean
- Kemudian masukan port 5432, maintenance database postgres, dan Username postgres lalu klik Save.
- Maka berhasil koneksi ke database PostgreSQL di Droplet DigitalOcean.
Silahkan buat database dan mebuat tabel.
Install extensi postgis
sudo apt install postgis postgresql-14-postgis-3
Misal buat database dan user
sudo -i -u postgres
lalu masuk ke postgrsql
createuser user123
createdb db_xxx -O user123
psql -d db_xxx
Menambahkan/menggati password untuk user1
ALTER USER user123 WITH PASSWORD password_baru
CREATE EXTENSION postgis;
Melihat List Database
\l
Pindah database
\c <nama_database>
List Table
\dt
Membuka port untuk Postgresql
sudo ufw allow <port>
Restart PostgreSQL
service postgresql restart
Referensi:
https://computingforgeeks.com/how-to-install-postgis-on-ubuntu-linux/
https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/
https://www.bigbinary.com/blog/configure-postgresql-to-allow-remote-connection
https://chartio.com/resources/tutorials/how-to-list-databases-and-tables-in-postgresql-using-psql/
0 comments:
Post a Comment