
Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria.
Hello, if you find this article helpful, you can express your gratitude through saweria.
How To
Add PostgreSQL repo automatis
sudo apt install -y postgresql-common sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.shInstall PostgreSQL
sudo apt install postgresqlUntuk membuat user dan database, gunakan
sudo -u postgres psqllalucreate user test_user with password 'testjuga123'; create database hapus_aja; grant all privileges on database hapus_aja to test_user; #list role \du #list database \lLalu agar database bisa di akses di luar host, buka file
/etc/postgresql/16/main/postgresql.conflisten_addresses = '*' #change this to * port = 666 # change default portSelanjutnya ubah file
sudo vim /etc/postgresql/16/main/pg_hba.conf, tambahkan user yang baru kita buathost all test_user 0.0.0.0/0 scram-sha-256Reload your PostgreSQL,
sudo service postgresql reloadCoba remote dengan
psql -U test_user -p 666 -W -h 192.168.1.66 -d hapus_aja.Kalau kamu cuma butuh PostgreSQL client, kamu bisa gunakan pgcli
sudo apt-get install pgcli. Untuk penggunaannya,pgcli -h 192.168.1.66 -U test_user -p 666 -d hapus_aja -W
Docker Setup
Kalau kamu butuh cepat, deploy di Docker itu lebih mudah
Buat file
docker-compose.ymlservices: postgres: image: postgres:16.1-alpine restart: always environment: POSTGRES_USER: admin POSTGRES_PASSWORD: password POSTGRES_DB: test_aja PGDATA: /data/postgres volumes: - postgres-db:/data/postgres ports: - "666:5432" networks: - "postgres-net" pgadmin4: image: dpage/pgadmin4 restart: always ports: - "6666:80" environment: - 'PGADMIN_DEFAULT_EMAIL=test_aja@domain.com' - 'PGADMIN_DEFAULT_PASSWORD=passwordLoch' - 'PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION=True' - 'PGADMIN_CONFIG_LOGIN_BANNER="Authorised users only!"' - 'PGADMIN_CONFIG_CONSOLE_LOG_LEVEL=10' networks: - "postgres-net" volumes: postgres-db: driver: local networks: postgres-net:Jalankan
docker compose up -d. Kamu bisa langsung remote database tanpa harus config apapunUntuk membuka pgAdmin, silakan buka
localhost:6666di browser
