MySQL DB #1 설치

개요

MySQL은 세계에서 가장 많이 쓰이는 오픈 소스의 관계형 데이터베이스 관리 시스템1(RDBMS : Relational DataBase Management System : 관계형 데이터베이스)이다. 다중 스레드, 다중 사용자 형식의 구조질의어 형식의 데이터베이스 관리 시스템으로서 오라클이 관리 및 지원하고 있으며, Qt처럼 이중 라이선스가 적용된다. 하나의 옵션은 GPL이며, GPL 이외의 라이선스로 적용시키려는 경우 전통적인 지적재산권 라이선스의 적용을 받는다.

위와 같은 지원 방식은 자유 소프트웨어 재단이 프로젝트에 저작권을 적용하는 방법과 비슷한 JBoss의 모델과 유사하다. 그러나 기반코드가 개인의 소유자에게 저작권이 있고 커뮤니티에 의해 개발되는 아파치 프로젝트와는 다르다.

MySQL AB는 또한 MaxDB라고 불리는 MySQL AB와는 기반코드가 다른 데이터베이스 관리 시스템을 판매했으나 2007년 이래로 MaxDB는 SAP AG가 소유하고 있다.

썬 마이크로시스템즈에 10억 달러에 인수되었으나, 썬 마이크로시스템즈가 오라클에 인수되며 같이 넘어갔다.2 위키백과에서 발췌

MySQL이 썬마이크로시스템즈->오라클로 넘어가면서 라이선스에 대한 이견으로 태어난 MariaDB3MariaDB는 오픈 소스의 관계형 데이터베이스 관리 시스템(RDBMS)이다. MySQL과 동일한 소스 코드를 기반으로 하며, GPL v2 라이선스를 따른다. 오라클 소유의 현재 불확실한 MySQL의 라이선스 상태에 반발하여 만들어졌으며, 배포자는 몬티 프로그램 AB(Monty Program AB)와 저작권을 공유해야 한다. 이것은 MySQL과 높은 호환성을 유지하기 위함이며, MySQL API와 명령에 정확히 매칭하여, 라이브러리 바이너리와 상응함을 제공하여 교체 가능성을 높이고자 함이다. 마리아 DB에는 새로운 저장 엔진인 아리아(Aria)뿐만 아니라, InnoDB를 교체할 수 있는 XtraDB 저장 엔진을 포함하고 있다. 이것은 트랜잭션과 비트랜잭션 엔진 그리고 미래에 나올 MySQL 판에 대응하고자 함일 것이다.
마리아 DB의 주요 개발자는 MySQL과 몬티 프로그램 AB를 설립한 몬티 와이드니어스(Michael Monty Widenius)이다. 그는 이전에 자신의 회사, MySQL AB를 썬 마이크로시스템즈에 10억 달러에 판매를 한 적이 있으며, 마리아 DB는 그의 둘째 딸인 마리아의 이름을 딴 것이다.
로 MySQL을 대체할 수 있다. 4RedHat Enterprise Linux와 CentOS의 느낌과 비슷한가?

설치

MySQL 8.x 는 보안 관련 기능 들이 많이 추가되었다. 사용자 생성이나 권한부여 등에서 5.x와 큰 차이가 있으니 유념하자.

다운로드
MySQL 홈페이지의 다운로드 페이지에서 Community Edition5GPL:GNU General Public Lisence을 선택하자. MariaDB 패키지는 이 링크에서 다운로드 할 수 있다.
여기에서 버전을 선택해서 다운로드 할 수도 있다.
어느 버전을 선택하건 RPM Bundle 을 선택하자. 6그래야 이런 저런 패키지를 따로 받아야 되는 귀찮음을 줄일 수 있다.

다운로드가 완료됐으면 서버에 파일을 업로드하자.

Install

업로드가 완료 되었으면 압축을 해제한다.

[centos7:/root/mysql:]# tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-5.7.31-1.el7.x86_64.rpm
mysql-community-client-5.7.31-1.el7.x86_64.rpm
mysql-community-server-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-5.7.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-common-5.7.31-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
mysql-community-devel-5.7.31-1.el7.x86_64.rpm
mysql-community-test-5.7.31-1.el7.x86_64.rpm
 # 기존에 설치된 mysql 또는 mariadb가 있을 경우 삭제하는 편이 좋다
[centos7:/root/mysql:]#  yum erase mariadb* mysql*
[centos7:/root/mysql:]# yum install ./*.rpm
Loaded plugins: fastestmirror, langpacks
Examining ./mysql-community-client-5.7.31-1.el7.x86_64.rpm: mysql-community-client-5.7.31-1.el7.x86_64
Marking ./mysql-community-client-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-common-5.7.31-1.el7.x86_64.rpm: mysql-community-common-5.7.31-1.el7.x86_64
Marking ./mysql-community-common-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-devel-5.7.31-1.el7.x86_64.rpm: mysql-community-devel-5.7.31-1.el7.x86_64
Marking ./mysql-community-devel-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-embedded-5.7.31-1.el7.x86_64.rpm: mysql-community-embedded-5.7.31-1.el7.x86_64
Marking ./mysql-community-embedded-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm: mysql-community-embedded-compat-5.7.31-1.el7.x86_64
Marking ./mysql-community-embedded-compat-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm: mysql-community-embedded-devel-5.7.31-1.el7.x86_64
Marking ./mysql-community-embedded-devel-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-libs-5.7.31-1.el7.x86_64.rpm: mysql-community-libs-5.7.31-1.el7.x86_64
Marking ./mysql-community-libs-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm: mysql-community-libs-compat-5.7.31-1.el7.x86_64
Marking ./mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-server-5.7.31-1.el7.x86_64.rpm: mysql-community-server-5.7.31-1.el7.x86_64
Marking ./mysql-community-server-5.7.31-1.el7.x86_64.rpm to be installed
Examining ./mysql-community-test-5.7.31-1.el7.x86_64.rpm: mysql-community-test-5.7.31-1.el7.x86_64
Marking ./mysql-community-test-5.7.31-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.56-2.el7 will be obsoleted
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-common.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-devel.x86_64 0:5.7.31-1.el7 will be obsoleting
---> Package mysql-community-embedded.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-embedded-compat.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-embedded-devel.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:5.7.31-1.el7 will be obsoleting
---> Package mysql-community-libs-compat.x86_64 0:5.7.31-1.el7 will be obsoleting
---> Package mysql-community-server.x86_64 0:5.7.31-1.el7 will be installed
---> Package mysql-community-test.x86_64 0:5.7.31-1.el7 will be installed
--> Processing Dependency: perl(JSON) for package: mysql-community-test-5.7.31-1.el7.x86_64
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * epel: ftp.jaist.ac.jp
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
--> Processing Dependency: perl(JSON) for package: mysql-community-test-5.7.31-1.el7.x86_64
--> Running transaction check
---> Package perl-JSON.noarch 0:2.59-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================
 Package                                   Arch             Version                  Repository                                                      Size
==========================================================================================================================================================
Installing:
 mysql-community-client                    x86_64           5.7.31-1.el7             /mysql-community-client-5.7.31-1.el7.x86_64                    101 M
 mysql-community-common                    x86_64           5.7.31-1.el7             /mysql-community-common-5.7.31-1.el7.x86_64                    2.8 M
 mysql-community-devel                     x86_64           5.7.31-1.el7             /mysql-community-devel-5.7.31-1.el7.x86_64                      20 M
     replacing  mariadb-devel.x86_64 1:5.5.56-2.el7
 mysql-community-embedded                  x86_64           5.7.31-1.el7             /mysql-community-embedded-5.7.31-1.el7.x86_64                  200 M
 mysql-community-embedded-compat           x86_64           5.7.31-1.el7             /mysql-community-embedded-compat-5.7.31-1.el7.x86_64            88 M
 mysql-community-embedded-devel            x86_64           5.7.31-1.el7             /mysql-community-embedded-devel-5.7.31-1.el7.x86_64            885 M
 mysql-community-libs                      x86_64           5.7.31-1.el7             /mysql-community-libs-5.7.31-1.el7.x86_64                      9.5 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat               x86_64           5.7.31-1.el7             /mysql-community-libs-compat-5.7.31-1.el7.x86_64               6.0 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                    x86_64           5.7.31-1.el7             /mysql-community-server-5.7.31-1.el7.x86_64                    762 M
 mysql-community-test                      x86_64           5.7.31-1.el7             /mysql-community-test-5.7.31-1.el7.x86_64                      663 M
Installing for dependencies:
 perl-JSON                                 noarch           2.59-2.el7               base                                                            96 k

Transaction Summary
==========================================================================================================================================================
Install  10 Packages (+1 Dependent package)

Total size: 2.7 G
Total download size: 96 k
Is this ok [y/d/N]: y
Downloading packages:
perl-JSON-2.59-2.el7.noarch.rpm                                                                                                    |  96 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.31-1.el7.x86_64                                                                                            1/13
  Installing : mysql-community-libs-5.7.31-1.el7.x86_64                                                                                              2/13
  Installing : mysql-community-devel-5.7.31-1.el7.x86_64                                                                                             3/13
  Installing : mysql-community-client-5.7.31-1.el7.x86_64                                                                                            4/13
  Installing : mysql-community-server-5.7.31-1.el7.x86_64                                                                                            5/13
  Installing : mysql-community-embedded-5.7.31-1.el7.x86_64                                                                                          6/13
  Installing : perl-JSON-2.59-2.el7.noarch                                                                                                           7/13
  Installing : mysql-community-test-5.7.31-1.el7.x86_64                                                                                              8/13
  Installing : mysql-community-embedded-devel-5.7.31-1.el7.x86_64                                                                                    9/13
  Installing : mysql-community-libs-compat-5.7.31-1.el7.x86_64                                                                                      10/13
  Installing : mysql-community-embedded-compat-5.7.31-1.el7.x86_64                                                                                  11/13
  Erasing    : 1:mariadb-devel-5.5.56-2.el7.x86_64                                                                                                  12/13
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                   13/13
  Verifying  : mysql-community-embedded-5.7.31-1.el7.x86_64                                                                                          1/13
  Verifying  : mysql-community-libs-compat-5.7.31-1.el7.x86_64                                                                                       2/13
  Verifying  : mysql-community-common-5.7.31-1.el7.x86_64                                                                                            3/13
  Verifying  : perl-JSON-2.59-2.el7.noarch                                                                                                           4/13
  Verifying  : mysql-community-embedded-compat-5.7.31-1.el7.x86_64                                                                                   5/13
  Verifying  : mysql-community-devel-5.7.31-1.el7.x86_64                                                                                             6/13
  Verifying  : mysql-community-server-5.7.31-1.el7.x86_64                                                                                            7/13
  Verifying  : mysql-community-test-5.7.31-1.el7.x86_64                                                                                              8/13
  Verifying  : mysql-community-embedded-devel-5.7.31-1.el7.x86_64                                                                                    9/13
  Verifying  : mysql-community-client-5.7.31-1.el7.x86_64                                                                                           10/13
  Verifying  : mysql-community-libs-5.7.31-1.el7.x86_64                                                                                             11/13
  Verifying  : 1:mariadb-devel-5.5.56-2.el7.x86_64                                                                                                  12/13
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                   13/13

Installed:
  mysql-community-client.x86_64 0:5.7.31-1.el7                                 mysql-community-common.x86_64 0:5.7.31-1.el7
  mysql-community-devel.x86_64 0:5.7.31-1.el7                                  mysql-community-embedded.x86_64 0:5.7.31-1.el7
  mysql-community-embedded-compat.x86_64 0:5.7.31-1.el7                        mysql-community-embedded-devel.x86_64 0:5.7.31-1.el7
  mysql-community-libs.x86_64 0:5.7.31-1.el7                                   mysql-community-libs-compat.x86_64 0:5.7.31-1.el7
  mysql-community-server.x86_64 0:5.7.31-1.el7                                 mysql-community-test.x86_64 0:5.7.31-1.el7

Dependency Installed:
  perl-JSON.noarch 0:2.59-2.el7

Replaced:
  mariadb-devel.x86_64 1:5.5.56-2.el7                                          mariadb-libs.x86_64 1:5.5.56-2.el7

Complete!

설정

[centos7:/root/mysql:]# vi /etc/my.cnf

 # 운영 목적에 맞는 설정을 추가해야 한다.
 # 모든 경로는 mysql계정과 그룹이 소유하고 있어야 한다.

[mysqld]

 # 접속을 받아들일 포트
port = 3306

 # 기본 캐릭터 셋
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci

 # MySQL Data가 저장될 경로
datadir=/home/mysql
 # MySQL 소켓 통신을 위한 socket 파일 경로
socket=/var/lib/mysql/mysql.sock

 # Error Log가 저장될 경로
log-error=/var/log/mysqld.log
 # 구동되는 MySQL 프로세스 ID 가 저장될 경로
pid-file=/var/run/mysqld/mysqld.pid


# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

구동

[centos7:/home/mysql:]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service

서비스 확인

[centos7:/home/mysql:]# ps -ef | grep mysql
mysql     24089      1  0 16:28 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root      26711   3609  0 16:38 pts/0    00:00:00 grep --color=auto mysql
[centos7:/home/mysql:]# netstat -nltp | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      24089/mysqld

패스워드 확인
root 계정에 대한 패스워드가 자동으로 생성된다. log 에서 확인 해야 한다.

[centos7:/home/mysql:]# grep password /var/log/mysqld.log
2020-12-11T07:24:57.633735Z 0 [Note] Shutting down plugin 'mysql_native_password'
2020-12-11T07:24:59.319129Z 1 [Note] A temporary password is generated for root@localhost: qT(2qk9c>y2G
2020-12-11T07:25:09.861956Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2020-12-11T07:25:23.483532Z 0 [Note] Shutting down plugin 'validate_password'
2020-12-11T07:25:24.495481Z 0 [Note] Shutting down plugin 'sha256_password'
2020-12-11T07:25:24.495490Z 0 [Note] Shutting down plugin 'mysql_native_password'

A temporary password is generated for root@localhost: 부분을 확인한다.
예시의 경우는 qT(2qk9c>y2G 가 패스워드이다.

TPC-H #1 . 준비

The TPC Benchmark™H (TPC-H) is a decision support benchmark. It consists of a suite of business oriented ad-hoc queries and concurrent data modifications.
라고 한다.
동일한 구조 동일한 데이터를 가진 테이블들을 대상으로 쿼리를 실행하여 하드웨어 성능을 비교할 때 사용한다. 1..고 한다. TPC 홈페이지에 가면 다양한 시험 방법을 제공한다.

설치
여타 소프트웨어의 설치와는 다르게 DBMS에 맞는 테이블 생성 쿼리와 샘플 데이터를 만드는 툴을 이용해 DDL과 샘플 데이터를 생성하는 것이 목적이다.
TPC 홈페이지에서 필요한 도구를 다운로드한다. 2예제는 tpc-h를 기준으로 한다. 계정,권한 관련 제한이 없으므로 아무 계정으로 다운로드 해서 진행 해도 무방하다.

PostgresQL에 테이블을 생성하고 데이터를 넣을 것이다.

dbgen(샘플데이터 생성기) 컴파일
압축 해제

[root@tpc tpc]$ ls
tpc-ds-tool.zip  tpc-h-tool.zip  v2.13.0rc1
[root@tpc tpc]# unzip tpc-h-tool.zip
...생략...
  inflating: 2.18.0_rc2/ref_data/300/supplier.tbl.19998
  inflating: 2.18.0_rc2/ref_data/300/supplier.tbl.29997
  inflating: 2.18.0_rc2/ref_data/300/supplier.tbl.30000
  inflating: 2.18.0_rc2/ref_data/300/supplier.tbl.9999
  inflating: 2.18.0_rc2/specification.docx
  inflating: 2.18.0_rc2/specification.pdf
[root@tpc tpc]$ ls
2.18.0_rc2  tpc-ds-tool.zip  tpc-h-tool.zip  v2.13.0rc1
[root@tpc tpc]$ cd 2.18.0_rc2
[root@tpc tpc]$ ls
EULA.txt  dbgen  dev-tools  ref_data  specification.docx  specification.pdf
[root@tpc 2.18.0_rc2]$ cd dbgen
[root@tpc 2.18.0_rc2]$ ls
BUGS           README   bcd2.h      check_answers    dbgen.dsp  dss.ddl  dsstypes.h      permute.c  qgen.c       reference  rnd.h    shared.h      text.c    tpch.sln           variants
HISTORY        answers  bm_utils.c  column_split.sh  dists.dss  dss.h    load_stub.c     permute.h  qgen.vcproj  release.h  rng64.c  speed_seed.c  tpcd.h    tpch.vcproj        varsub.c
PORTING.NOTES  bcd2.c   build.c     config.h         driver.c   dss.ri   makefile.suite  print.c    queries      rnd.c      rng64.h  tests         tpch.dsw  update_release.sh

dbgen 컴파일을 위한 설정 파일 수정

 # makefile 생성
[root@tpc dbgen]$ cp    makefile.suite      makefile
[root@tpc dbgen]$ vi     makefile
 # 컴파일러,  대상 DBMS종류, 시스템 종류, workload 정보를 변경한다.
 # CC = , DATABASE = , MACHINE = , WORKLOAD = 항목을 찾는다.
 # 리눅스에 설치된 ORACLE 을 기준으로 다음과 같이 변경. (아래 주석 참고)
CC      = gcc
DATABASE= ORACLE
MACHINE = LINUX
WORKLOAD = TPCH
# Current values for DATABASE are: INFORMIX, DB2, TDAT (Teradata)
#                                  SQLSERVER, SYBASE, ORACLE, VECTORWISE
# Current values for MACHINE are:  ATT, DOS, HP, IBM, ICL, MVS,
#                                  SGI, SUN, U2200, VMS, LINUX, WIN32
# Current values for WORKLOAD are:  TPCH

컴파일 및 확인
dbgen 파일이 생성되면 정상적으로 컴파일이 된 것이다.

[root@tpc dbgen]$  make
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o build.o build.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o driver.o driver.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o bm_utils.o bm_utils.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o rnd.o rnd.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o print.o print.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o load_stub.o load_stub.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o bcd2.o bcd2.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o speed_seed.o speed_seed.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o text.o text.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o permute.o permute.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o rng64.o rng64.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64  -O -o dbgen build.o driver.o bm_utils.o rnd.o print.o load_stub.o bcd2.o speed_seed.o text.o permute.o rng64.o -lm
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o qgen.o qgen.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64    -c -o varsub.o varsub.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64  -O -o qgen build.o bm_utils.o qgen.o rnd.o varsub.o text.o bcd2.o permute.o speed_seed.o rng64.o -lm
[root@tpc dbgen]$  ll
total 920
...중략...
-rwxr-xr-x 1 root root 111910 Aug  2 13:01 dbgen
-rw-r--r-- 1 root root   5154 Dec  5  2018 dbgen.dsp
...중략...
-rwxr-xr-x 1 root root 103060 Aug  2 13:01 qgen
-rw-r--r-- 1 root root  14404 Dec  5  2018 qgen.c
-rw-r--r-- 1 root root  48984 Aug  2 13:01 qgen.o
-rw-r--r-- 1 root root   4916 Dec  5  2018 qgen.vcproj
drwxr-xr-x 2 root root   4096 Feb 18 12:03 queries
-rw-r--r-- 1 root root  17617 Dec  5  2018 README

※ TPC-H는 정확하게 PostgresQL용 쿼리를 제공하지 않는다. ORACLE용 쿼리와 데이터를 생성하고 이를 이용해 PostgresQL에 데이터를 넣을 것이다.

데이터 및 테스트 쿼리 생성
dbgen을 실행하면 실험용 쿼리와 데이터가 자동으로 생성된다.

# 데이터 및 쿼리 생성
[root@tpc dbgen]$  ./dbgen
TPC-H Population Generator (Version 3.0.0)
Copyright Transaction Processing Performance Council 1994 - 2010
 # 편의를 위해 쿼리파일과 샘플 데이터를 한곳으로 옮긴다.
[root@tpc dbgen]# mkdir data
[root@tpc dbgen]# cp *.ddl data/
[root@tpc dbgen]# cp *.tbl data/
# 확인 - 중간에 dss.ddl 파일에 테이블 생성 스크립트가 존재한다.
[root@tpc dbgen]$ ll data
total 1074924
-rw-r--r-- 1 root root  24346144 Aug  2 13:07 customer.tbl
-rw-r--r-- 1 root root      3814 Dec  5  2018 dss.ddl
-rw-r--r-- 1 root root 759863287 Aug  2 13:07 lineitem.tbl
-rw-r--r-- 1 root root      2224 Aug  2 13:07 nation.tbl
-rw-r--r-- 1 root root 171952161 Aug  2 13:07 orders.tbl
-rw-r--r-- 1 root root 118984616 Aug  2 13:07 partsupp.tbl
-rw-r--r-- 1 root root  24135125 Aug  2 13:07 part.tbl
-rw-r--r-- 1 root root       389 Aug  2 13:07 region.tbl
-rw-r--r-- 1 root root   1409184 Aug  2 13:07 supplier.tbl
[root@tpc dbgen]$ ll queries/
total 88
-rw-r--r-- 1 root root  646 Dec  5  2018 10.sql
-rw-r--r-- 1 root root  631 Dec  5  2018 11.sql
-rw-r--r-- 1 root root  720 Dec  5  2018 12.sql
-rw-r--r-- 1 root root  470 Dec  5  2018 13.sql
-rw-r--r-- 1 root root  442 Dec  5  2018 14.sql
-rw-r--r-- 1 root root  641 Dec  5  2018 15.sql
-rw-r--r-- 1 root root  609 Dec  5  2018 16.sql
-rw-r--r-- 1 root root  411 Dec  5  2018 17.sql
-rw-r--r-- 1 root root  581 Dec  5  2018 18.sql
-rw-r--r-- 1 root root 1090 Dec  5  2018 19.sql
-rw-r--r-- 1 root root  666 Dec  5  2018 1.sql
-rw-r--r-- 1 root root  711 Dec  5  2018 20.sql
-rw-r--r-- 1 root root  804 Dec  5  2018 21.sql
-rw-r--r-- 1 root root  797 Dec  5  2018 22.sql
-rw-r--r-- 1 root root  815 Dec  5  2018 2.sql
-rw-r--r-- 1 root root  518 Dec  5  2018 3.sql
-rw-r--r-- 1 root root  474 Dec  5  2018 4.sql
-rw-r--r-- 1 root root  605 Dec  5  2018 5.sql
-rw-r--r-- 1 root root  363 Dec  5  2018 6.sql
-rw-r--r-- 1 root root  926 Dec  5  2018 7.sql
-rw-r--r-- 1 root root  900 Dec  5  2018 8.sql
-rw-r--r-- 1 root root  741 Dec  5  2018 9.sql

테이블 생성

PostgresQL은 텍스트파일3i.e. csv 파일을 import 할 때 문자열 끝에 구분자가 있으면 컬럼이 하나 더 있는 것으로 인식한다. 따라서 이를 위한 dummy column 을 추가한다.

-- 더미 컬럼에는 데이터가 들어가지 않는다. 따라서 붙여넣기 하다가 not null 도 따라 붙여 넣지 않도록 주의한다.

CREATE TABLE public.NATION  ( N_NATIONKEY  INTEGER NOT NULL,
                            N_NAME       CHAR(25) NOT NULL,
                            N_REGIONKEY  INTEGER NOT NULL,
                            N_COMMENT    VARCHAR(152),
                            N_DUMMY   VARCHAR(1));
                           
CREATE TABLE public.REGION  ( R_REGIONKEY  INTEGER NOT NULL,
                            R_NAME       CHAR(25) NOT NULL,
                            R_COMMENT    VARCHAR(152),
                            R_DUMMY VARCHAR(1));

CREATE TABLE public.PART  ( P_PARTKEY     INTEGER NOT NULL,
                          P_NAME        VARCHAR(55) NOT NULL,
                          P_MFGR        CHAR(25) NOT NULL,
                          P_BRAND       CHAR(10) NOT NULL,
                          P_TYPE        VARCHAR(25) NOT NULL,
                          P_SIZE        INTEGER NOT NULL,
                          P_CONTAINER   CHAR(10) NOT NULL,
                          P_RETAILPRICE DECIMAL(15,2) NOT NULL,
                          P_COMMENT     VARCHAR(23) NOT null,
                          P_DUMMY VARCHAR(1));

CREATE TABLE public.SUPPLIER ( S_SUPPKEY     INTEGER NOT NULL,
                             S_NAME        CHAR(25) NOT NULL,
                             S_ADDRESS     VARCHAR(40) NOT NULL,
                             S_NATIONKEY   INTEGER NOT NULL,
                             S_PHONE       CHAR(15) NOT NULL,
                             S_ACCTBAL     DECIMAL(15,2) NOT NULL,
                             S_COMMENT     VARCHAR(101) NOT NULL,
                             S_DUMMY    VARCHAR(1));

CREATE TABLE public.PARTSUPP ( PS_PARTKEY     INTEGER NOT NULL,
                             PS_SUPPKEY     INTEGER NOT NULL,
                             PS_AVAILQTY    INTEGER NOT NULL,
                             PS_SUPPLYCOST  DECIMAL(15,2)  NOT NULL,
                             PS_COMMENT     VARCHAR(199) NOT NULL, );

CREATE TABLE public.CUSTOMER ( C_CUSTKEY     INTEGER NOT NULL,
                             C_NAME        VARCHAR(25) NOT NULL,
                             C_ADDRESS     VARCHAR(40) NOT NULL,
                             C_NATIONKEY   INTEGER NOT NULL,
                             C_PHONE       CHAR(15) NOT NULL,
                             C_ACCTBAL     DECIMAL(15,2)   NOT NULL,
                             C_MKTSEGMENT  CHAR(10) NOT NULL,
                             C_COMMENT     VARCHAR(117) NOT NULL,
                             C_DUMMY VARCHAR(1));

CREATE TABLE public.ORDERS  ( O_ORDERKEY       INTEGER NOT NULL,
                           O_CUSTKEY        INTEGER NOT NULL,
                           O_ORDERSTATUS    CHAR(1) NOT NULL,
                           O_TOTALPRICE     DECIMAL(15,2) NOT NULL,
                           O_ORDERDATE      DATE NOT NULL,
                           O_ORDERPRIORITY  CHAR(15) NOT NULL,
                           O_CLERK          CHAR(15) NOT NULL,
                           O_SHIPPRIORITY   INTEGER NOT NULL,
                           O_COMMENT        VARCHAR(79) NOT NULL,
                           O_DUMMY VARCHAR(1));

CREATE TABLE public.LINEITEM ( L_ORDERKEY    INTEGER NOT NULL,
                             L_PARTKEY     INTEGER NOT NULL,
                             L_SUPPKEY     INTEGER NOT NULL,
                             L_LINENUMBER  INTEGER NOT NULL,
                             L_QUANTITY    DECIMAL(15,2) NOT NULL,
                             L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL,
                             L_DISCOUNT    DECIMAL(15,2) NOT NULL,
                             L_TAX         DECIMAL(15,2) NOT NULL,
                             L_RETURNFLAG  CHAR(1) NOT NULL,
                             L_LINESTATUS  CHAR(1) NOT NULL,
                             L_SHIPDATE    DATE NOT NULL,
                             L_COMMITDATE  DATE NOT NULL,
                             L_RECEIPTDATE DATE NOT NULL,
                             L_SHIPINSTRUCT CHAR(25) NOT NULL,
                             L_SHIPMODE     CHAR(10) NOT NULL,
                             L_COMMENT      VARCHAR(44) NOT NULL,
                             L_DUMMY VARCHAR(1));

데이터 입력

※ 테이블 명, 컬럼명 등은 대소문자 구분을 하지 않지만 소스 파일 명 및 경로는 대소문자를 구분하므로 주의한다.

COPY public.nation(N_NATIONKEY,N_NAME,N_REGIONKEY,N_COMMENT,N_dummy)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/nation.tbl'
DELIMITER '|'
;

COPY public.region(R_REGIONKEY,R_NAME,R_COMMENT,R_DUMMY)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/region.tbl'
DELIMITER '|'
;

COPY public.part(P_PARTKEY,P_NAME,P_MFGR,P_BRAND,P_TYPE,P_SIZE,P_CONTAINER,P_RETAILPRICE,P_COMMENT,P_DUMMY VARCHAR)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/part.tbl'
DELIMITER '|'
;

COPY public.supplier(S_SUPPKEY,S_NAME,S_ADDRESS,S_NATIONKEY,S_PHONE,S_ACCTBAL,S_COMMENT)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/supplier.tbl'
DELIMITER '|'
;

COPY public.partsupp(PS_PARTKEY,PS_SUPPKEY,PS_AVAILQTY,PS_SUPPLYCOST,PS_COMMENT,PS_DUMMY)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/partsupp.tbl'
DELIMITER '|'
;

COPY public.customer(C_CUSTKEY,C_NAME,C_ADDRESS,C_NATIONKEY,C_PHONE,C_ACCTBAL,C_MKTSEGMENT,C_COMMENT,C_dummy)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/customerp.tbl'
DELIMITER '|'
;
                           
COPY public.orders(O_ORDERKEY,O_CUSTKEY,O_ORDERSTATUS,O_TOTALPRICE,O_ORDERDATE,O_ORDERPRIORITY,O_CLERK,O_SHIPPRIORITY,O_COMMENT,O_DUMMY)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/orders.tbl'
DELIMITER '|'
;

COPY public.lineitem(L_ORDERKEY,L_PARTKEY,L_SUPPKEY,L_LINENUMBER,L_QUANTITY,L_EXTENDEDPRICE,L_DISCOUNT,L_TAX,L_RETURNFLAG,L_LINESTATUS,L_SHIPDATE,L_COMMITDATE,L_RECEIPTDATE,L_SHIPINSTRUCT,L_SHIPMODE,L_COMMENT,L_DUMMY)
FROM '/home/tpc/2.18.0_rc2/dbgen/sample/lineitem.tbl'
DELIMITER '|'
;

확인

 # 실행 예
 # PostgresQL import 문법이므로 기억하자
tpc=$ COPY public.customer(c_custkey,c_name,c_address,c_nationkey,c_phone,c_acctbal,c_mktsegment,c_comment,c_dummy)
tpc-$ FROM '/home/tpc/2.18.0_rc2/dbgen/sample/region.tbl'
tpc-$ DELIMITER '|'
tpc-$ ;
COPY 150000
tpc=$
 # 확인
tpc=$ select count(*) from public.customer;
 count
--------
 150000
(1개 행)

tpc=$ select * from public.customer limit 1;
 c_custkey |       c_name       |     c_address     | c_nationkey |     c_phone     | c_acctbal | c_mktsegment |                           c_comment                            | c_dummy
-----------+--------------------+-------------------+-------------+-----------------+-----------+--------------+----------------------------------------------------------------+---------
         1 | Customer#000000001 | IVhzIApeRb ot,c,E |          15 | 25-989-741-2988 |    711.56 | BUILDING     | to the even, regular platelets. regular, ironic epitaphs nag e |
(1개 행)

tpc=$ \dt
       릴레이션(relation) 목록
 스키마 |   이름   |  종류  | 소유주
--------+----------+--------+--------
 public | customer | 테이블 | tpc
 public | lineitem | 테이블 | tpc
 public | nation   | 테이블 | tpc
 public | orders   | 테이블 | tpc
 public | part     | 테이블 | tpc
 public | partsupp | 테이블 | tpc
 public | region   | 테이블 | tpc
 public | supplier | 테이블 | tpc
(8개 행)

tpc=$

PostgresQL #.2 설정

인터페이스 변경

이전 포스트에서 구동 한 PostgresQL서버는 기본 값 loopbak(127.0.0.1) 인터페이스로 구동 되었다. 외부 연결을 위해서는 서비스 리슨 인터페이스를 변경 해 줘야 한다.
Listen 인터페이스 관련 설정은 postgresql.conf 파일에 정의 돼 있다. 이전 포스트의 내용대로 설치 했을 경우 설정 파일은 /var/lib/pgsql/12/data 아래에 존재한다. 1설치 할 때의 조건에 따라 /etc/postgresql/version 디렉토리 아래에 존재할 수 도 있다.

[postgres@centos7:/home/]$  vi /var/lib/pgsql/12/data/postgresql.conf
 
 # 아래 "listen_addresses"와 "port" 값을 변경해 주면 되는데 주석처리가 돼 있으므로 파일 끝에 새 값을 삽입한다.
      ... 중략...
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

# - TCP settings -
# see "man 7 tcp" for details

#tcp_keepalives_idle = 0                # TCP_KEEPIDLE, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_interval = 0            # TCP_KEEPINTVL, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_count = 0               # TCP_KEEPCNT;
                                        # 0 selects the system default
    ....중략...

 # 여기부터 파일 끝에 삽입한다.
listen_addresses = '0.0.0.0'
 # 인터페이스가 여러개일 경우 0.0.0.0을 입력하면 모든 인터페이스가 연결을 받아들이고
 # 특정 IP를 입력하면 지정한 IP로만 연결이 가능한다.
port = 5432                         

인증 방법 설정

 # 패스워드 인증을을 통한 접속 허용을 위한 설정
[postgres@centos7:/home/]$  vi /var/lib/pgsql/12/data/pg_hba.conf
 # 파일의 끝에 아래를 붙여넣기 한다.

host    all             all             0.0.0.0/0               md5
#호스트를 기준으로 모든 계정을 이용해 모든 IP에서 들어오는 연결에 대해 패스워드 인증을 허용하는 설정이다.
 #인터페이스 관련 설정을 변경할 경우 재기동이 필요하다.
[postgres@centos7:/home/]$  /usr/pgsql-12/bin/pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log stop
[postgres@centos7:/home/]$  /usr/pgsql-12/bin/pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log start

계정 생성

 # 생성하는 계정에 관리자 권한을 부여할 때
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/createuser psqluser --interactive
createuser dataware --interactive
새 롤을 superuser 권한으로 지정할까요? (y/n) y
 # 관리자 권한을 부여하지 않을 때.
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/createuser psqluser --interactive
새 롤을 superuser 권한으로 지정할까요? (y/n) n
이 새 롤에게 데이터베이스를 만들 수 있는 권할을 줄까요? (y/n) y
이 새 롤에게 또 다른 롤을 만들 수 있는 권한을 줄까요? (y/n) y
 # SQL을 이용한 사용자 생성
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/psql
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# CREATE USER datauser WITH ENCRYPTED PASSWORD 'password';
CREATE ROLE
postgres=#

데이터 베이스 생성

[postgres@centos7:/home/]$   /usr/pgsql-12/bin/psql
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# CREATE DATABASE data OWNER data ENCODING 'utf-8';
CREATE ROLE
postgres=#

접속 확인

 # postgres 가 아닌 다른 계정으로 시도해본다. 원격지에서도 가능하다.
root@centos7:/home/]#   psql -U dataware -W -h localhost

다음과 같이 입력을 쉘이 변하면 정상 구동 중인 상태

암호:
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# select * from pg_tables;
     schemaname     |        tablename        | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
--------------------+-------------------------+------------+------------+------------+----------+-------------+-------------
 pg_catalog         | pg_statistic            | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_type                 | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_foreign_server       | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_authid               | postgres   | pg_global  | t          | f        | f           | f
 pg_catalog         | pg_statistic_ext_data   | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_user_mapping         | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_subscription         | postgres   | pg_global  | t          | f        | f           | f
 pg_catalog         | pg_attribute            | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_proc                 | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_class                | postgres   |            | t          | f        | f           | f
... 중략...
 information_schema | sql_sizing_profiles     | postgres   |            | f          | f        | f           | f
(70개 행)

PostgresQL #.1 설치 및 구동

개요

PostgreSQL은 확장 가능성 및 표준 준수를 강조하는 객체-관계형 데이터베이스 관리 시스템(ORDBMS)의 하나이다. BSD 허가권으로 배포되며 오픈소스 개발자 및 관련 회사들이 개발에 참여하고 있다. 데이터베이스 서버로서 주요 기능은 데이터를 안전하게 저장하고 다른 응용 소프트웨어로부터의 요청에 응답할 때 데이터를 반환하는 것이이다. 소규모의 단일 머신 애플리케이션에서부터 수많은 동시 접속 사용자가 있는 대형의 인터넷 애플리케이션(또는 데이터 웨어하우스용)에 이르기까지 여러 부하를 관리할 수 있으며 macOS 서버의 경우 PostgreSQL은 기본 데이터베이스이다. 마이크로소프트 윈도우, 리눅스(대부분의 배포판에서 제공됨)용으로도 이용 가능하다. PostgresQL의 전신은 Ingres DB로 실제 프로젝트의 공식 명칭은 “post-Ingres” 데이터베이스이다.

설치

Postgresql 사이트에서 yum 리포지터리 RPM을 다운로드 받을 수 있다.

이렇게 제공된다. 아래 텍스트를 복사-붙여넣기 하여 설치하면 된다.
 # repository RPM 설치
 # 설치하면 postgresql repo 파일이 /etc/yum.repos.d 아래 생성된다.
[root@centos7:/root/]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 # PostgresQL 설치
[root@centos7:/root/]# yum install -y postgresql12-server
 
 # 이렇게 설치 해도 된다.
[root@centos7:/root/]# yum install -y postgresql12-*

초기화
initdb를 이용해 데이터 디렉토리 생성 및 지정이 필요하다.
postgresql 서버를 설치하면 postgres 계정이 자동으로 생성되고 DBMS의 최고 권한은 이 postgres 계정이 가지게 된다. 서버 프로세스의 구동부터 모든 작업이 postgres 계정으로 진행되어야 하므로 디렉토리 생성등을 할 경우 postgres 계정에 모든 권한을 부여해야 한다.

 # DB 초기화 등 작업

 # 초기화 :  /var/lib/pgsql/12/data 가 데이터 디렉토리로 '자동'지정된다.
[postgres@centos7:/home/]$ /usr/pgsql-12/bin/initdb 
이 데이터베이스 시스템에서 만들어지는 파일들은 그 소유주가 "postgres" id로
지정될 것입니다. 또한 이 사용자는 서버 프로세스의 소유주가 됩니다.

데이터베이스 클러스터는 "ko_KR.UTF-8" 로케일으로 초기화될 것입니다.
기본 데이터베이스 인코딩은 "UTF8" 인코딩으로 설정되었습니다.
initdb: "ko_KR.UTF-8" 로케일에 알맞은 전문검색 설정을 찾을 수 없음
기본 텍스트 검색 구성이 "simple"(으)로 설정됩니다.

자료 페이지 체크섬 기능 사용 하지 않음

이미 있는 /var/lib/pgsql/12/data 디렉터리의 액세스 권한을 고치는 중 ...완료
하위 디렉터리 만드는 중 ...완료
사용할 동적 공유 메모리 관리방식을 선택하는 중 ... posix
max_connections 초기값을 선택하는 중 ...100
기본 shared_buffers를 선택하는 중... 128MB
기본 지역 시간대를 선택 중 ... Asia/Seoul
환경설정 파일을 만드는 중 ...완료
부트스트랩 스크립트 실행 중 ... 완료
부트스트랩 다음 초기화 작업 중 ... 완료
자료를 디스크에 동기화 하는 중 ... 완료

initdb: 경고: 로컬 접속용 "trust" 인증을 설정 함
이 값을 바꾸려면, pg_hba.conf 파일을 수정하든지,
다음번 initdb 명령을 사용할 때, -A 옵션 또는 --auth-local,
--auth-host 옵션을 사용해서 인증 방법을 지정할 수 있습니다.

작업완료. 이제 다음 명령을 이용해서 서버를 가동 할 수 있습니다:

    ./pg_ctl -D /var/lib/pgsql/12/data -l 로그파일 start
# 초기화 : -pgdata= 로 지정한 디렉토리가 지정된다. 
 # 이경우 지정한 디렉토리의 소유자는 postgres이어야 하고 모든 권한을 가져야 한다.
[root@centos7:/home/]# mkdir /home/postgres
[root@centos7:/home/]# chown -R postgres /home/postgres
 # 쉘에 주의하자 여기까지는 root 이다.
[postgres@centos7:/home/]$ mkdir /home/postgres/data
[postgres@centos7:/home/]$ /usr/pgsql-12/bin/initdb  --pgdata=/home/postgres/data

/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

구동
initdb 작업 결과의 명령대로 구동하면 된다.

[postgres@centos7:/home/]$ /usr/pgsql-12/bin//pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log start
서버를 시작하기 위해 기다리는 중.... 완료
서버 시작됨

확인

[root@host0 bin]# netstat -nltp |grep postgres
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      96383/postgres