반응형

/***************************************************************************************
-- Title : [Pgs9.2] PostgreSQL 수동 설치 - ver.dBRang
-- Reference : 웹검색
-- Key word : postgres postgresql 설치 installation install 수동설치 수동 설치 DB설치 DB 설치
***************************************************************************************/

-- 1. OS 환경

root# arch
i686

root# cat /etc/redhat-release
CentOS release 6.4 (Final)

root# df -k

-- 2. 관련 패키지 설치(필요시, 아래와 같은 에러 발생시)
    ㅇ configure: error: readline(또는 zlib 등등) library not found If you have readline already
        installed, see config.log
        for details on the failure.  It is possible the compiler isn't looking in the proper directory.
        Use --without-readline to disable readline support.
    ㅇ 왜 readline이나 zlib 패키지가 없다는데 xxx-devel을 설치해야 하는지 모르겠다??

root# yum -y install gcc gcc-c++ make autoconf wget readline readline-devel zlib zlib-devel openssl openssl-devel gettext gettext-devel python python-devel

-- 3. PostgreSQL 다운로드
    ㅇ http://www.postgresql.org/ftp/source 에서 확인.

root# cd /usr/local/src
root# wget http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.gz

root# tar zxvf postgresql-9.2.4.tar.gz

-- 4. postgres 사용자 생성

root# useradd -d /home/postgres postgres -- 사용자 등록
root# cat /etc/passwd -- 사용자 등록 확인

root# passwd postgres -- 패스워드 생성
root# pwconv -- 패스워드 적용

-- 5. postgres사용자의 .bash_profile 변경
    ㅇ export PATH 위치에 주의

root# su - postgres
postgres$ vi .bash_profile

# BOF
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

POSTGRES_HOME=/home/postgres/pgsql
PGLIB=$POSTGRES_HOME/lib
PGDATA=$POSTGRES_HOME/data
MANPATH=$MANPATH:$POSTGRES_HOME/man

PATH=$POSTGRES_HOME/bin:$PATH

export PATH
export POSTGRES_HOME
export PGLIB
export PGDATA
export MANPATH

# I do not know why $PGLIB is not working. 
# but once some error(.. cannot open shared object...) occured,
# I have solved this problem with adding below two sentences.
LD_LIBRARY_PATH=/home/postgres/pgsql/lib
export LD_LIBRARY_PATH

# EOF

postgres$ source .bash_profile
postgres$ exit
root#

 

 

-- 6. PostgreSQL 설치

root# cd /usr/local/src/postgresql-9.2.4
root# ./configure --prefix=/home/postgres/pgsql --enable-depend --enable-nls=ko --with-python

    ㅇ 설치 디렉토리 : /home/postgres/pgsql
    ㅇ ./configure : 시스템에 맞추어 소스 트리를 설정(설치를 위한 Makefile 생성), 소스파일에 대한 환경 설정 명령어.
    ㅇ Configure Opion : http://www.postgresql.org/docs/9.2/static/install-procedure.html
    ㅇ Error나 Warning이 뜰 경우 "# yum install gcc bison flex"처럼 패키지 설치 후 재실행.

root# make              -- Start Build
root# make check    -- Regression Test
root# make install    -- Install PostgreSQL
-- 또는
root# make && make install

    ㅇ make : 소스를 컴파일해서 실행 가능한 파일로 생성.(setup 실행 파일 생성과 비슷)
    ㅇ make install : make에서 만들어진 setup 파일을 실행해서 설치.

-- 7. 데이터베이스 초기화 폴더(data) 디렉토리 추가 및 권한 부여

root# mkdir -p /home/postgres/pgsql/data
root# chown -R postgres.postgres /home/postgres/pgsql

-- 8. 데이터베이스 클러스터 생성

postgres$ su - postgres
postgres$ cd /home/postgres/pgsql/bin
postgres$ ./initdb -E utf-8 -D /home/postgres/pgsql/data

    ㅇ -E : character set, 인코딩 언어셋
    ㅇ -D : postgresql 기본 설정 파일 설치
    ㅇ ./initdb : 데이터베이스 클러스터(sql server의 시스템db?) 생성
  
-- 8. 데이터베이스 가동
    ㅇ <FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": 허가 거부> 이런 메시지시
        /tmp/.s.PGSQL.5432*을 삭제 후 진행
        참고 :

http://dbrang.tistory.com/737

postgres$ cd /home/postgres/pgsql/bin
postgres$ ./postgres -D /home/postgres/pgsql/data &
    또는
postgres$ ./pg_ctl -D /home/postgres/pgsql/data -l logfile start

-- 9. DB 가동 확인
    postgres$ ps -ef |grep postgres

    postgres$ pg_ctl status
        pg_ctl: server is running (PID: 18719)
        /home/postgres/pgsql/bin/postgres

-- 10. SuperUser 생성

postgres$ psql
postgres=# create role {account} login password '{password}' superuser;
postgres=# \q

-- 11. postgresql.conf 파일 변경

postgres$ vi /home/postgres/pgsql/data/postgresql.conf 에서
    #listen_addresses = 'localhost' → listen_addresses = '*' 로 변경

-- 12. pg_hba.conf 파일 변경

postgres$ vi /home/postgres/pgsql/data/pg_hba.conf 에서
    host    all    all    172.20.20.0/24    md5
    host    all    all    192.20.20.0/24    password 추가

-- 13. DB 재시작

postgres$ cd   -- 왠만하면 logfile을 Home Directory에 남길려고
postgres$ pg_ctl -D /home/postgres/pgsql/data -l logfile restart

-- 16. 방화벽 포트 오픈

root# vi /etc/sysconfig/iptables 에서
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT 추가


-- 17. 방화벽 재시작

root# service iptables restart


-- 18. 기본 접근 및 SELECT

root# su - postgres
postgres$ psql
postgres=# select * from pg_database;


-- 19. 사용자 테이블스페이스 생성

root# mkdir /home/database                      -- 사용자 TBS Root dir.
root# mkdir /home/database/ARCHIVE       -- WAL Archive dir.
root# mkdir /home/database/tbs_data0       -- TBS dir.
root# mkdir /home/database/tbs_data1       -- TBS dir.
root# mkdir /home/database/tbs_data2       -- TBS dir.
root# mkdir /home/database/tbs_data3       -- TBS dir.

root# chown postgres.postgres /home/database   -- 소유자 변경

root# su - postgres
postgres$  psql

-- 테이블스페이스 생성

postgres=# create tablespace tbs_data0 owner sys location '/home/database/tbs_data0';
postgres=# create tablespace tbs_data0 owner sys location '/home/database/tbs_data1';

postgres=# create tablespace tbs_data0 owner sys location '/home/database/tbs_data2';
postgres=# create tablespace tbs_data0 owner sys location '/home/database/tbs_data3';

-- TBS 생성 확인
postgres=# select * from pg_tablespace; 

-- 20. 최초 PostgreSQL Cold Backup

postgres=# \q
postgres$ pg_ctl stop
postgres$ exit
root# mkdir /home/backup

root# cd /home/postgres
root# tar czf /home/backup/bak_pgsql.tar.gz ./pgsql 

root# cd /home
root# tar czf /home/backup/bak_database.tar.gz ./database 

반응형

+ Recent posts