[Ubuntu] install PostgreSQL
https://wikidocs.net/7369
https://zetawiki.com/wiki 설치
설치
0. 기설치여부 확인
1. 설치
https://www.postgresql.org/download/linux/ubuntu/
http://yallalabs.com/linux/how-to-install-and-use-postgresql-10-on-ubuntu-16-04/
Add repository
Import the repository signing key
Ver10.1 설치
2. 설치확인
PostgreSQL 관리자 계정 postgres
가 생성되었음
postgres:x:122:129:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
3. 상태 확인
● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled) Active: active (exited) since 화 2017-08-22 14:50:21 KST; 20h ago Process: 1598 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 1598 (code=exited, status=0/SUCCESS) CGroup: /system.slice/postgresql.service
로컬호스트(127.0.0.1)에서만 접속 가능
초기설정
psql 관리툴 접속
패스워드 설정
postgres 계정의 패스워드 변경
psql 종료
설정파일
설정파일 (/etc/postgresql/9.5/main/ 폴더내)
postgresql.conf : PostgreSQL configuration file
pg_hba.conf : PostgreSQL Client Authentication Configuration File
pg_ctl.conf : Automatic pg_ctl configuration
pg_ident.conf : PostgreSQL User Name Maps
start.conf : Automatic startup configuration
postgresql.conf
– 모든 IP(*)에서 5432 포트 접근 가능하도록 설정
# CONNECTIONS AND AUTHENTICATION listen_addresses = '*'
pg_hba.conf
– 모든 IP(0.0.0.0/0)에서 모든 DB(all)에 대해 모든 계정(all)으로 로그인 허용
# IPv4 local connections: #host all all 127.0.0.1/32 md5 host all all 0.0.0.0/0 md5
PostgreSQL 재시작 후 LISTEN 포트 확인
추가 설정
사용자 매핑 목록
Role 목록
데이터베이스 목록
데이터베이스 추가
사용자 생성
Role 부여
joe 사용자로 testdb 데이터베이스에 연결한다.
CF> 명시적으로 호스트 접속 부분을 쓰지 않으면, psql: FATAL: Peer authentication failed for user "egg"
같이 에러가 발생한다.
이때는 /etc/postgresql/9.5/main/ 폴더내에 pg_hba.conf 파일에서, [PostgreSQL Client Authentication Configuration File]
md5 방법으로 접속 가능 사용자를 지정한다.
# 추가 local all egg md5 # TYPE DATABASE USER ADDRESS METHOD local all postgres peer local all all peer host all all 127.0.0.1/32 md5 host all all ::1/128 md5
이렇게 예외 사용자를 추가하기 위해서는 반드시 윗줄에 적어야 한다.