PostgreSQL

오픈소스 비즈니스 컨설팅
둘러보기로 가기 검색하러 가기

PostgreSQL 8.3.1에 대한 전반적인 사항을 정리한다.
일반적으로 널리 사용되는 관계형 데이터베이스이다.


추가 컴포넌트 설치

  • "Application Stack Builder" 메뉴를 선택하여 PostgreSQL에서 사용할 추가 컴포넌트를 설치한다.


  • 컴포넌트를 설치할 데이터베이스를 선택한다.
데이터베이스 지정


  • 데이터베이스에 접속하기 위한 드라이버를 선택한다.
  • .NET으로 접속하기 위해 "Npgsql v1.0.0"을 선택한다.
  • Java로 접속하기 위해 "psqlJDBC v8.3.603"을 선택한다.
ODBC로 접속하기 위해 "psqlODBC v08.03.0100"을 선택한다.
드라이버 선택


  • 컴포넌트를 다운로드할 사이트를 선택한다.
다운로드 사이트 선택


  • 다운로드한 컴포넌트를 임시 보관할 디렉토리를 지정한다.
임시 보관 디렉토리


  • "Next" 버튼을 눌러 컴포넌트의 설치를 시작한다.
컴포넌트 설치 시작


PostgreSQL .NET Provider (Npgsql) 설치

  • "Next" 버튼을 눌러 설치를 시작한다.
설치 시작


  • 라이센스를 확인한다.
라이센스 확인


  • 설치할 디렉토리를 지정한다.
설치 디렉토리


  • "Install" 버튼을 눌러 설치를 시작한다.
설치 시작


  • "Finish" 버튼을 눌러 설치를 종료한다.
설치 종료


psqlODBC 설치

  • "Next" 버튼을 눌러 설치를 시작한다.
설치 시작


  • 라이센스를 확인한다.
라이센스


  • 설치할 디렉토리를 지정한다.
설치 디렉토리


  • "Install" 버튼을 눌러 설치를 시작한다.
설치 시작


  • "Finish" 버튼을 눌러 설치를 종료한다.
설치 종료


PostgreSQL JDBC Drivers (psqlJDBC) 설치

  • "Next" 버튼을 눌러 설치를 시작한다.
설치 시작


  • 라이센스를 확인한다.
라이센스


  • 설치할 디렉토리를 지정한다.
설치 디렉토리


  • "Install" 버튼을 눌러 설치를 시작한다.
설치 시작


  • "Finish" 버튼을 눌러 설치를 종료한다.
설치 종료


  • "Finish" 버튼을 눌러 컴포넌트의 설치를 완료한다.
설치 완료


Linux용 설치 가이드

Ubuntu Server 8.10에서 PostgreSQL을 정리한다.

  • PostgreSQL 8.3 설치
  • sudo apt-get install postgresql
  • PostgreSQL의 Super User를 등록 한다.
su postgres
createuser -P 관리자_아이디     //--- 관리자로 사용할 아이디를 등록 한다
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
  • 설치 정보
  • 설치 폴더 : /usr/lib/postgresql/8.3/
  • 환경 폴더 : /etc/postgresql/8.3/main, /etc/postgresql-common
  • 데이터 폴더 :
  • 작업 폴더 : /var/lib/postgresql/
  • 로그 폴더 : /var/log/postgresql/
  • 기동 종료 : /etc/init.d/postgresql-8.3 start, stop, restart, status
  • 서비스 확인 : ps -ef | grep postgre
  • 로그 정보 :
  • postgres 사용자의 홈 디렉토리 : /var/lib/postgresql

CentOS용 설치 가이드

  • CentOS에서 PostgreSQL 설치
#--- CentOS에 root로 로그인 한다.
yum -y install postgresql postgresql-server postgresql-odbc postgresql-jdbc postgresql-devel
rpm -qa | grep postgresql    #--- postgresql 설치 확인
  • 설치 정보
  • 설치 폴더 : /usr/share/pgsql/
  • 데이터 폴더 : /var/lib/pgsql/
  • 실행 파일 : /usr/bin/
  • 기동 종료 : /etc/init.d/postgresql start, stop, restart 또는 service postgresql start, stop, restart
  • 서비스 확인 : ps -ef | grep postmaster | grep -v grep

사용자 가이드

  • PostgreSQL Database Server를 시작/종료하는 방법
"시작" 메뉴에서 "설정" 메뉴를 선택한 후 "제어판"을 선택한다.
"관리 도구"를 더블 클릭한 후 "서비스"를 더블 클릭한다.
시작 종료
"PostgreSQL Database Server 8.3"을 선택한 후 오른쪽 마우스를 클릭하여 PostgreSQL Database Server를 시작하거나 중지(종료)할 수 있다.


관리자 가이드

CentOS에서 DB Schema 추가 설정

#--- useridDB : 데이터베이스명
#--- userid : 데이터베이스의 사용자 아이디
#--- userpassword : userid의 암호
su - postgres
createuser -s -l userid
createdb useridDB
psql
    alter user userid with encrpted password 'userpassword';
    alter database useridDB owner to userid;

백업 및 복구

  • DB별 백업 및 복구
su - postgres
pg_dumpall -f db_all.out                                              //--- DB 전체 백업
pg_dump mydb > mydb.sql
pg_dump -h localhost -U postgres -Ft -f mydb.backup mydb              //--- DB 백업
pg_dump -h localhost -U postgres -Ft -f mydb.backup -t zipcode mydb   //--- 테이블 백업
pg_restore -l mydb.backup > mydb.toc   //--- 내용 보기
pg_restore -h localhost -U postgres -Ft -d mydb mydb.backup           //--- DB 복구
//--- mydb.toc에서 복구가 필요없는 자료는 삭제하거나 ;로 표시한 후 아래 명령을 실행한다.
pg_restore -h localhost -U postgres -L mydb.toc -d mydb mydb.backup   //--- 부분 복구
  • PostgreSQL database의 백업 및 복구
  • postgres 사용자로 백업 시
su - postgres
pg_dumpall -f db_backup.sql
psql -d ${DB_NAME} < db_backup.sql
  • root 사용자로 백업 시 (DB_NAME. 데이터베이스 명, DB_USER. 데이터베이스 사용자)
su - root
pg_dump -h 127.0.0.1 -U ${DB_USER} -W -b -f db_backup.sql ${DB_NAME}
psql -h 127.0.0.1 -U ${DB_USER} -W -d ${DB_NAME} < db_backup.sql

라이센스

  • PostgreSQL, Slony, & JDBC are released under the BSD License.
  • GridSQL is released under the GPLv2 with the following license exception.
  • psqlODBC & Npgsql are released under the LGPL.
  • pgAdmin III is released under the Artistic Licence.
  • PostGIS & phpPgAdmin Server are released under the GPLv2.
  • PHP is released under the PHP License.
  • The Apache Webserver is released under the Apache License.
  • This product includes software released under the OpenSSL License.
  • This product includes Kerberos software released under the MIT License.


psql

    Database 
        jdbc:postgresql://localhost:5432/opencell_db
        opencell_db_user / opencell_db_password
        
        jdbc:postgresql://10.0.0.14:5432/meveo


    psql --host=10.0.0.14 --port=5432 --username=meveo --password --dbname=meveo
        \?                              : 도움말
        \h                              : SQL 명령어
        \l                              : Database 목록
        \d      \d+                     : Relationship 정보
        \dS                             : System Table
        \dt                             : Database table
        select relname as table_name from pg_stat_user_tables;
        select table_name, column_name, data_type, column_default from information_schema.columns where table_catalog = 'meveo' and table_name = 'rating_edr' order by ordinal_position;
        \dv                             : View
        \dn                             : Schema
        \e                              : Query 수정 후 실행
        \q                              : 종료
    pg_dump --host=10.0.0.14 --port=5432 --username=meveo --password --dbname=meveo > meveo.sql
    pg_restore --schema-only -v dumpfile

참고 문헌