IT/👨‍💻Computer Science

PostgreSQL 설치

지식모아이령 2023. 1. 27. 16:52

기본 설치

$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib

#postgresql를 설치하면 기본적으로 postgres라는 계정이 생성되고 이 계정으로 접근해야한다.
$ sudo su postgres
$ psql

CREATE USER [name];
ALTER USER {user_name} WITH SUPERUSER;  #슈퍼유저 권한으로 변경

#postgresql에서는 DB명과 동일한 linux 유저 계정이 필요합니다.
CREATE DATABASE [name];

$ adduser [name]; # DB명과 동일한 linux 유저 생성

 

외부접속 허용

1) postgresql.conf 파일 수정

  • listen_addresses = '*' 로 변경

2) pg_hba.conf 파일 수정

  • Pv4 local connections 에서 host의 ADDRESS를 0.0.0.0/0으로 변경

3) postgresql 재시작

  • systemctl restart postgresql
  • netstat -nap | grep 5432 확인 (postgresql의 기본 포트는 5432)