brunch

[CentOS 6] Postgresql 소스 설치

postgresql 9.5.7 - 명령어 기반 설치 가이드 & 팁 정리

by K의 단상

Postgresql 소스 설치 정리

1. 계정 생성

$> adduser postgres

2. postgres 계정으로 로그인

$> su - postgres

3. postgresql 소스 다운로드와 압축 해제

$> wget https://ftp.postgresql.org/pub/source/v9.5.7/postgresql-9.5.7.tar.gz

$> tar xvfz postgresql-9.5.7.tar.gz

$> cd postgresql-9.5.7

4. postgresql 설정 & 설치 진행

$> ./configure --prefix=/home/postgres/pgsql // prefix는 설치 디렉터리 지정

$> make

$> make install

5. 기본 DB 설치 & 접속 테스트

$> cd /home/postgres/pgsql/bin

$> ./initdb -D /home/postgres/pgsql/data

$> ./postgres -D /home/postgres/pgsql/data/ >logfile 2>&1 &

$> ./psql test

Postgresql 기동 & 재기동 & 정지

1. 기동 중지를 위한 pg_ctl 명령어 사용하기

$> cd /home/postgres/pgsql/bin

$> ./pg_ctl status -D /home/postgres/pgsql/data //상태 확인

$> ./pg_ctl restart -D /home/postgres/pgsql/data //재기동 start, stop 사용 가능


Postgresql 접속 설정

로컬에서 암호를 이용해 pgsql 접속 설정

$> vi /home/postgres/pgsql/data/pg_hba.conf

local all all peer --> local all all md5 수정

외부 접속 허용

1. iptable OPEN

$> iptables -I INPUT 1 -p tcp --dport 5432 -j ACCEPT

$> iptables -I OUTPUT 1 -p tcp --dport 5432 -j ACCEPT

2. postgresql.conf 수정

$> vi /home/postgres/pgsql/data/postgresql.conf

listen_addresses = 'localhost' --> listen_addresses = '*' 수정

3. pg_hba.conf 내용 추가

$> vi /home/postgres/pgsql/data/pg_hba.conf

host all all 0.0.0.0/0 password //password 방식으로 모든 IP 인증


DB 사용 정보

사용자 추가 & 비밀번호 설정 & DB 권한 설정

1. 사용자 추가

$> /home/postgres/pgsql/bin/createuser {ID}

2. 비밀번호 설정

$> /home/postgres/pgsql/bin/psql

postgres=# alter user {ID} with encrypted password '{PASSWORD}';

3. DB 권한 부여

$> /home/postgres/pgsql/bin/psql

postgres=# grant all privileges on database {database} unusdev to {ID};


tablespace 생성

$> mkdir /home/postgres/pgsql/test_tablespace

$> /home/postgres/pgsql/bin/psql

postgres=# create tablespace test_tblspc location '/home/postgres/pgsql/test_tablespace';


DATABASE 생성

1. /home/postgres/pgsql/bin/createdb {database}

2. pgsql에서 DB 변경

$> /home/postgres/pgsql/bin/psql

postgres=# \c {database}

3. 데이터베이스 목록 보기

$> /home/postgres/pgsql/bin/psql

postgres=# \l+

4. 테이블 목록 보기

$> /home/postgres/pgsql/bin/psql

postgres=# \d


DATABASE 백업 & 복구

1. 백업

$> /home/postgres/pgsql/bin/pg_dumpall -U postgres -f output_filename

2. 복구

$> /home/postgres/pgsql/bin/psql -U postgres -f output_filename


keyword
작가의 이전글Spring Controller 문서 만들기