Saturday, March 2, 2019

PostgreSQL on CentOS 7

1. 필요한 팩키지들을 yum으로 설치
$ sudo yum install postgresql-server postgresql-contrib

2. PostgreSQL database cluster를 생성
$ sudo postgresql-setup initdb

3. 설치한 PostgreSQL 시작
$ sudo systemctl start postgresql

4. os 시작시 PostgreSQL 시작
$ sudo systemctl enable postgresql

5. PostgreSQL 계정 설정
postgres 사용자로 전환하고
$ su - postgres

사용자를 추가하고
$ createuser user_name --interactive

사용자의 패스워드를 설정함
$ alter user user_name with password 'password';

6. PostgreSQL 외부 접속
외부 접속을 하기 위해서는 PostgreSQL 설정을 변경해야 하는데, 이를 위해서 접속 가능한 ip와 인증 방법을 설정해야 함. 이를 위해 다음의 파일을 열어서
$ sudo vi /var/lib/pgsql/data/pg_hba.conf

모든 ip에서 접속 가능하게 하고 password 인증을 설정
host all all 0.0.0.0/0 password

PostgreSQL에서 모든 연결을 수신할 수 있도록 다음 파일을 열어서
$ sudo vi /var/lib/pgsql/data/postgresql.conf

listen_addresses를 전체로 설정
listen_addresses = '*'

그 이후에는 PostgreSQL를 다시 시작하고 외부 접속하면 잘 됨
$ sudo systemctl restart postgresql