• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[CentOS 6]Postgresql 소스 기반으로 설치하기

01 Jun 2017

Reading time ~1 minute

Postgresql 소스 설치 정리

  1. 계정 생성
    1. $> adduser postgres
  2. postgres 계정으로 로그인
    1. $> su - postgres
  3. postgresql 소스 다운로드와 압축 해제
    1. $> wget https://ftp.postgresql.org/pub/source/v9.5.7/postgresql-9.5.7.tar.gz
    2. $> tar xvfz postgresql-9.5.7.tar.gz
    3. $> cd postgresql-9.5.7
  4. postgresql 설정 & 설치 진행
    1. $> ./configure –prefix=/home/postgres/pgsql // prefix 는 설치 디렉토리 지정
    2. $> make
    3. $> make install
  5. 기본 DB 설치 & 접속 테스트
    1. $> cd /home/postgres/pgsql/bin
    2. $> ./initdb -D /home/postgres/pgsql/data
    3. $> ./postgres -D /home/postgres/pgsql/data/ >logfile 2>&1 &
    4. $> ./psql test

Postgresql 기동 & 재기동 & 정지

  • 기동 중지를 위한 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
    1. $> iptables -I INPUT 1 -p tcp –dport 5432 -j ACCEPT
    2. $> iptables -I OUTPUT 1 -p tcp –dport 5432 -j ACCEPT
  2. postgresql.conf 수정
    1. $> vi /home/postgres/pgsql/data/postgresql.conf
    2. listen_addresses = ‘localhost’ –> listen_addresses = ‘*’ 수정
  3. pg_hba.conf 내용 추가
    1. $> vi /home/postgres/pgsql/data/pg_hba.conf
    2. host all all 0.0.0.0/0 password //password 방식으로 모든 IP 인증

DB 사용 정보

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

  1. 사용자 추가
    1. $> /home/postgres/pgsql/bin/createuser {ID}
  2. 비밀번호 설정
    1. $> /home/postgres/pgsql/bin/psql
    2. postgres=# alter user {ID} with encrypted password ‘{PASSWORD}’;
  3. DB 권한 부여
    1. $> /home/postgres/pgsql/bin/psql
    2. postgres=# grant all privileges on database {database} unusdev to {ID};

tablespace 생성

  1. $> mkdir /home/postgres/pgsql/test_tablespace
  2. $> /home/postgres/pgsql/bin/psql
  3. postgres=# create tablespace test_tblspc location ‘/home/postgres/pgsql/test_tablespace’;

DATABASE 생성

  1. /home/postgres/pgsql/bin/createdb {database}
  2. pgsql 에서 DB 변경
    1. $> /home/postgres/pgsql/bin/psql
    2. postgres=# \c {database}
  3. 데이터베이스 목록 보기
    1. $> /home/postgres/pgsql/bin/psql
    2. postgres=# \l+
  4. 테이블 목록 보기
    1. $> /home/postgres/pgsql/bin/psql
    2. postgres=# \d

DATABASE 백업 & 복구

  1. 백업
    1. $> /home/postgres/pgsql/bin/pg_dumpall -U postgres -f output_filename
  2. 복구
    1. $> /home/postgres/pgsql/bin/psql -U postgres -f output_filename


postgresql Share Tweet +1