Test Code/Linux

[Ubuntu 14.04 Server] PostgreSql 설치 및 설정

yaks101 2014. 4. 30. 09:26

** Ubuntu server + PostgreSql


1. Ubuntu server 설치시 마지막에 postgresql server 선택하여 설치를 완료한다.

설치되어 있지 않다면

> sudo apt-get install postgresql-9.3


2. postgresql.conf 수정


> sudo vi /etc/postgresql/9.3/main/postgresql.conf

listen_addresses = '*'


3. pg_hba.conf 수정

> sudo vi /etc/postgresql/9.3/main/pg_hba.conf 

# Database administrative login by UNIX sockets

local   all         postgres                          md5


# IPv4 local connection: 추가

  # 모든 IP 접속을 해야하는경우는 0.0.0.0/0

host all all 192.168.0.2/32 md5


4. postgres 로 로그인


> sudo -u postgres psql


5. postgres 비밀번호 변경

postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD '1'

postgres=# \q  


6. postgresql 재시작

# > sudo /etc/init.d/postgresql stop

> sudo /etc/init.d/postgresql restart


7. Database 생성

postgres=# CREATE USER test WITH PASSOWRD '1'

postgres=# CREATE DATABASE test

postgres=# \q  

# database 삭제

# DROP DATABASE test


8. Database 접속

psql -U test -h localhost --dbname='test'

# 비밀번호 변경하기

# test=# ALTER USER test  WITH ENCRYPTED PASSWORD '1'



**. 서버 종료

> sudo shutdown -h 0