[postgreSQL] 원격 서버(Ubuntu)와 pgAdmin4 연결하고 접속하기
원격 서버에 postgreSQL이 설치만 되어있는 상황
서버환경
우분투 20.04
postgreSQL 12
로컬환경
window 10
postgreSQL 설치 (원격)
sudo apt-get update
sudo apt-get install postgresql
관련 설정 경로)
/etc/postgresql/12/main
방화벽 & 외부접근 허용 설정
우분투)
sudo ufw allow 5432 # 방화벽 열기
sudo systemctl enable postgresql #재시작
postgreSQL)
- postgresql.conf
# vim으로 편집할 경우
vim /etc/postgresql/12/main/postgresql.conf
listen_addresses = '*' # 모든 접근 허용
- pg_hba.conf
vim /etc/postgresql/12/main/pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 0.0.0.0/0 trust # 수정한 부분
# IPv6 local connections:
host all all ::1/128 trust # 수정한 부분
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
host all all 0.0.0.0/0 trust # 추가한 부분
pg_hba 설정에서 워낙 헤매서 참고한 블로그도 같이 공유!
참고)
pgAdmin 4 설치 (로컬)
https://www.pgadmin.org/download/pgadmin-4-windows/
Download
pgAdmin 4 (Windows) Download Maintainer: pgAdmin Development Team pgAdmin is available for 64 bit Windows™ 7 SP1 (desktop) or 2008R2 (server) and above, up to v4.30. v5.0 and later are supported on Windows 8 (desktop) or 2012 (server) and above. v7.0 and
www.pgadmin.org
exe 파일 다운로드 받아서 실행하면 화면이 나옵니다
add New Server 클릭 > General 설정
Connection 설정
SSH Tunnel 설정
원격서버에서 방화벽이나 ssh 설정을 미리 해주어야합니다.
연결 완료!
왼쪽 창을 통해서 Server연결과 DB, Table에 대해 탐색하면 됩니다.
참고)
PostgreSQL 설치 및 세팅 & pgAdmin 사용법 - Windows
pgAdmin4 및 DBeaver에서 원격 데이터베이스에 연결하는 방법