[Ubuntu] install PostgreSQL

Published by onesixx on

https://wikidocs.net/7369
https://zetawiki.com/wiki 설치

설치

0. 기설치여부 확인

Shell

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 

Shell

Import the repository signing key

Shell

Ver10.1 설치

Shell

2. 설치확인

Shell

 PostgreSQL 관리자 계정 postgres가 생성되었음

Shell
postgres:x:122:129:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

3. 상태 확인

Shell
● 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)에서만 접속 가능

Shell

 초기설정

psql 관리툴 접속 

Shell

패스워드 설정

postgres 계정의 패스워드 변경

SQL

psql 종료

SQL

설정파일  

설정파일 (/etc/postgresql/9.5/main/ 폴더내)

Shell

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

Shell

postgresql.conf 

– 모든 IP(*)에서 5432 포트 접근 가능하도록 설정

Shell
# CONNECTIONS AND AUTHENTICATION
listen_addresses = '*'

pg_hba.conf

– 모든 IP(0.0.0.0/0)에서 모든 DB(all)에 대해 모든 계정(all)으로 로그인 허용

Shell
# IPv4 local connections:
#host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0            md5

PostgreSQL 재시작 후 LISTEN 포트 확인

Shell

추가 설정

사용자 매핑 목록

SQL

Role 목록

SQL

데이터베이스 목록

SQL

데이터베이스 추가

SQL

사용자 생성

SQL

Role 부여 

SQL

joe 사용자로 testdb 데이터베이스에 연결한다.

Shell

CF> 명시적으로 호스트 접속 부분을 쓰지 않으면, psql: FATAL: Peer authentication failed for user "egg"같이 에러가 발생한다. 

Shell

이때는  /etc/postgresql/9.5/main/ 폴더내에 pg_hba.conf 파일에서, [PostgreSQL Client Authentication Configuration File]

Shell

 md5 방법으로 접속 가능 사용자를 지정한다.

Shell
# 추가
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

이렇게 예외 사용자를 추가하기 위해서는 반드시 윗줄에 적어야 한다.

적용을 위한 재시작

Shell
Categories: Postgresql

onesixx

Blog Owner

guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x