티스토리 뷰

postgresql DB생성 및 접속 시 Peer authentication에러 발생 시 해야할 것

참조: https://www.postgresql.org/docs/9.5/static/auth-pg-hba-conf.html

현상 확인: 에러 메시지

DB 생성할 때

zipeya@postgresql:~$ createdb -U postgres testdb
createdb: could not connect to database template1: FATAL:  Peer authentication failed for user "postgres"
zipeya@postgresql:~$ psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"
zipeya@postgresql:~$

psql로 접속할 때

zipeya@postgresql:~$ psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"
zipeya@postgresql:~$

조치사항

pg_hba.conf파일 설정을 변경해야한다.

로컬일 경우

$ zipeya@postgresql:~$ sudo vi /etc/postgresql/9.5/main/pg_hba.conf
...
local   all             all                                      peer
...

peer를 md5로 변경하고 서비스 재시작

zipeya@postgresql:~$ sudo service postgresql restart
zipeya@postgresql:~$ createdb -U postgres testdbb
Password:
zipeya@postgresql:~$ psql -U postgres
Password for user postgres:
psql (9.5.1)
Type "help" for help.

postgres=# \l testdb
                              List of databases
  Name  |  Owner   | Encoding |   Collate   |    Ctype    | Access privileges
--------+----------+----------+-------------+-------------+-------------------
 testdb | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(1 row)

postgres=# \q

동일하게 Peer authentication에러가 뜬다면 pg_hba.conf파일에 아래와 같이 해당 계정(postgres)등에 걸려있는 인증방법을 확인해보기 바랍니다.

$ zipeya@postgresql:~$ sudo vi /etc/postgresql/9.5/main/pg_hba.conf
...
local   all             postgres                                      peer
...

외부 host기준으로는 아래와 같이..

$ zipeya@postgresql:~$ sudo vi /etc/postgresql/9.5/main/pg_hba.conf
...
host    all             all             127.0.0.1/32            md5
...

127.0.0.1/32 md5를 0.0.0.0/0 md5로 변경하고, postgresql.conf의 listen_addresses항목을 아래와 같이 변경한다.

$ zipeya@postgresql:~$ sudo vi /etc/postgresql/9.5/main/postgresql.conf
...
listen_addresses = '*' 
...

postgresql 서비스를 재시작하고 외부에서도 잘 접속되는지 확인해봅니다.

zipeya@postgresql:~$ sudo service postgresql restart

잘 되지요?

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함