문서유형ㅣ기술정보
분야ㅣ유틸리티
적용제품버전ㅣTibero 6 이상
문서번호ㅣTUTTI017
개요
쉘 스크립트는 tbSQL 유틸리티를 통해 튜닝 진행 시 trace 활성화, DBMS_XPLAN 확인 , tbprof 분석 세 가지 기능에 대해 자동 완성 기능을 제공합니다. 이로인해 번거로운 작업을 최소화 하여 튜닝에 집중할 수 있는 장점이 있습니다. 본 문서에서는 tbProfiler.sh 에 대한 내용을 소개합니다.
tbProfiler.sh 개요
tbProfiler.sh 쉘 스크립트는 LINUX 환경에서만 동작하며 TIBERO 6버전 이상 사용을 권장합니다.
- LINUX : RHEL7.9 ↑ CentOS 7.9 ↑
- TIBERO : 6 ↑
본 문서에서 다루는 tbProfiler.sh 230217 버전이며 Github Repositories에서 지속적으로 기능 개선 및 오류 수정을 진행하고 있습니다.
참고
간단한 설명은 하기 github URL의 readme를 참고하시기 바랍니다.
https://github.com/younjunsu/tbProfiler
방법
tbProfiler.sh 주요 기능
- 자동 trace option 적용 리스트 제공
- 자동 DBMS_XPLAN 수행 결과 출력
- 자동 SQL TRACE 파일 tbprof 유틸리티 분석 결과 출력
tbProfiler.sh 설정
1. tbprofiler.sh 및 tbsql.login 파일 준비
- tbProfiler.tar.gz 파일 다운로드 > 서버 업로드 > 압축 해제 > tbProfiler.sh.tbsql.log 파일 확인 - Github 내에 tbProfiler.sh, tbsql.login 파일 다운로드 > 서버 업로드 > tbProfiler.sh,tbsql.login 파일 확인 - 작업 디렉토리는 위치에 상관 없으며 tbsql 실행 권한이 있어야 합니다. - tbProfiler.sh 및 tbsql.login 두 개 파일이 동일한 디렉토리에 존재해야 합니다. total 24 -rw-r--r--. 1 ps1 psall 526 Feb 17 2023 tbsql.login -rwxr--r--. 1 ps1 psall 15165 Feb 17 2023 tbProfiler.sh
2. tbprofiler.sh 설정
# user configuration #-------------------------------------------------------------------------------- TBSQL_USER="" TBSQL_PASSWORD="" TB_SQLPATH="" SQL_TRACE_FILE_PATH="" #-------------------------------------------------------------------------------- #TB_NLS_LANG=UTF8 #LANG=ko_KR.utf8 #stty erase ^H #stty erase ^? #--------------------------------------------------------------------------------
- tbProfier.sh 파일을 vi로 편집하여 몇 가지 파라미터를 설정합니다.
필수 설정
- TBSQL_USER = tbSQL 사용 유저
- TBSQL_PASSWORD = tbSQL 사용 유저 암호
- TB_SQLPATH = tbsql.login 파일 위치 및 작업 디렉토리 경로
- SQL_TRACE_FILE_PATH = SQL_TRACE=Y 옵션에 의해 생성되는 파일의 디렉토리 경로
선택 설정
- TB_NLS_LANG=tbSQL에 사용될 client character set
- LANG = 터미널 에뮬레이터에서 표현될 LANG
- stty erase ^H or ^? 백스페이스 수행 시 문자 삭제 시그널
example
# user configuration #-------------------------------------------------------------------------------- TBSQL_USER="tibero" TBSQL_PASSWORD="tmax" TB_SQLPATH="/sdiske/ps1/tbProfiler230217" SQL_TRACE_FILE_PATH="/sdiske/ps1/tibero7/instance/tb7/log/sqltrace" #-------------------------------------------------------------------------------- #TB_NLS_LANG=UTF8 #LANG=ko_KR.utf8 #stty erase ^H #stty erase ^? #--------------------------------------------------------------------------------
tbProfiler.sh 사용
tbProfiler.sh 실행 설명
[ps1@psdblcbp:/sdiske/ps1/tbProfiler230217]$ sh tbProfiler.sh ############################### tbProfiler mode help message ############################### usage: sh tbProfiler.sh [option] ----------------------------- run : start tbsql Profiler help : help message -----------------------------
옵션 없이 실행 또는 help 명령 실행 시 help message가 출력됩니다.
tbPRofiler.sh 실행
###############################
# tbProfiler mode options
###############################
- TIBERO VERSION : Tibero 7 (DB 7.2.4) Build 303704
- TIBERO USER : tibero
- TB_SQLPATH : /sdiske/ps1/soi/tbProfiler230217
- SQL_TRACE_FILE_PATH : /sdiske/ps1/soi/tibero7/instance/tb7/log/sqltrace
- TB_NLS_LANG :
- DB CHARACTERSET_NAME : UTF8
- DB NCHAR_CHARACTERSET_NAME : UTF16
-----------------------------
sql tbprof file count : 0
- /sdiske/ps1/soi/tbProfiler230217
sql trace file count : 0
- /sdiske/ps1/soi/tibero7/instance/tb7/log/sqltrace
-----------------------------
###############################
# Please select the trace option.
###############################
- set autot on exp stat plans : 1
- set autot on : 2
- set autot on exp : 3
- set autot on stat : 4
- set autot on plans : 5
- set autot trace exp stat plans : 6
- set autot trace : 7
- set autot trace exp : 8
- set autot trace stat : 9
- set autot trace plans : 10
-----------------------------
- quit : q
-----------------------------
- other key no trace
-----------------------------
press key : 3
tbProfiler mode options
- TIBER VERSION : TIBERO 버전
- TBIERO USER : tbsql에 로그인한 유저
- TB_SQLPATH : tbsql.login 파일 경로 및 작업 디렉토리 경로
- SQL_TRACE_FILE_PATH : SQL_TRACE=Y 파라미터에 의해 dump 되는 trc 파일의 경로
- B_NLS_LANG : tbsql client CHARSET
- DB_CHARACTERSET_NAME : server CHARSET
- DB NCHAR_CHARACTERSET_NAME : server NCHARSET
- sql tbprof file count : tbprof out file 개수
- sql trace file count : sql trace file 개수
Please select the trace option
- set autot on exp stat plans : 옵티마이저 실행 플랜, 실행 통계, 실행 결과 / SQL 결과 출력
- set autot on : 옵티마이저 실행 플랜, 실행 통계 / SQL 결과 출력
- set autot on exp : 옵티마이저 실행 플랜 / SQL 결과 출력
- set autot on stat : 옵티마이저 실행 통계 / SQL 결과 출력
- set autot on plans : 옵티마이저 실행 결과 / SQL 결과 출력
- set autot trace exp stat plans : 옵티마이저 실행 플랜, 실행 통계, 실행 결과 / SQL 결과 미출력
- set autot trace : 옵티마이저 실행 플랜, 실행 통계 / SQL 결과 미출력
- set autot trace exp : 옵티마이저 실행 플랜 / SQL 결과 미출력
- set autot trace stat : 옵티마이저 실행 통계 / SQL 결과 미출력
- set autot trace plans : 옵티마이저 실행 결과 / SQL 결과 미출력
tbProfier.sh SQL 수행
############################### # tbsql.loing options apply ############################### Spooling is started. TBPROF SID SERIAL# PID ---------- ---------- ---------- ---------- tbprofinfo 103 1379426 29659 ############################# # Please execute the query. ############################# select * from dual; DUMMY ----- X 1 row selected. Total elapsed time 00:00:00.015651 SQL ID: a5ks9fhw2v9s1 Child number: 6966 Plan hash value: 3480736023 Execution Plan ---------------------------------------------------------------------------------------------------- 1 DPV: _VT_DUAL (Cost:1, %%CPU:0, Rows:1) ############################### # TIBERO XPLAN ############################### SQL ID : a5ks9fhw2v9s1 CHILD NUMBER : 6966 HASH VALUE : 942515969 PLAN HASH VALUE: 3480736023 EXECUTIONS : 1 FETCHES : 1 LOADED AT : 2025/11/18 10:25:53 TOT ELAPSED TIME: 00:00:00.0068 AVG ELAPSED TIME: 00:00:00.0068 TOT BUFFER GETS: 0 AVG BUFFER GETS: 0 SQL : select * from dual ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ID | Operation | Name | Cost (%CPU) | Cards | Rows | Elaps. Time | BUFGETS | Starts | Used Mem | Temp. Read | Temp. Write| Reads | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | 1 | DPV | _VT_DUAL | 1 (0)| 1 | 1 |00:00:00.0000 | 0 | 1 | 0K | 0 | 0 | 0 | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- LAST ELAPSED TIME: 00:00:00.0000
tbsql.login options apply
- tbsql.login 파일에 지정된 tbSQL 옵션 적용 (자동)
Please execute the query.
- Query 입력
- Query 재수행 q 하지 않고 재 입력
- Query XPLAN 확인 q Enter (마지막으로 수행 된 Query의 XPLAN)
tbProfier mode menu
###############################
# tbProfiler mode menu
###############################
- tbProfiler : re
- tbprof : tr
- quit : q
-----------------------------
other key retry.
-----------------------------
press key :
tbProfiler mode menu
- re : 수행 시 tbProfiler 최초 실행 메뉴로 이동
- tr : tbprof 수행
- q : tbProfiler 종료
tbProfiler mode menu "re"
###############################
# tbProfiler mode menu
###############################
- tbProfiler : re
- tbprof : tr
- quit : q
-----------------------------
other key retry.
-----------------------------
press key : re
###############################
# tbProfiler mode options
###############################
- TIBERO VERSION : Tibero 7 (DB 7.2.4) Build 303704
- TIBERO USER : tibero
- TB_SQLPATH : /sdiske/ps1/tbProfiler230217
- SQL_TRACE_FILE_PATH : /sdiske/ps1/tibero7/instance/tb7/log/sqltrace
- TB_NLS_LANG :
- DB CHARACTERSET_NAME : UTF8
- DB NCHAR_CHARACTERSET_NAME : UTF16
-----------------------------
sql tbprof file count : 0
- /sdiske/ps1/tbProfiler230217
sql trace file count : 1
- /sdiske/ps1/tibero7/instance/tb7/log/sqltrace
-----------------------------
###############################
# Please select the trace option.
###############################
- set autot on exp stat plans : 1
- set autot on : 2
- set autot on exp : 3
- set autot on stat : 4
- set autot on plans : 5
- set autot trace exp stat plans : 6
- set autot trace : 7
- set autot trace exp : 8
- set autot trace stat : 9
- set autot trace plans : 10
-----------------------------
- quit : q
-----------------------------
- other key no trace
-----------------------------
press key :
- re 수행 시 tbProfiler 최초 실행 메뉴로 이동
tbProfiler mode menu "tr"
###############################
# tbProfiler mode menu
###############################
- tbProfiler : re
- tbprof : tr
- quit : q
-----------------------------
other key retry.
-----------------------------
press key : tr
###############################
# tbprof extract
###############################
progress : -(90%)
TBPROF 7
TmaxTibero Corporation Copyright (c) 2020-. All rights reserved.
TmaxTibero Corporation Copyright (c) 2020-. All rights reserved.
input file name : /sdiske/ps1/tibero7/instance/tb7/log/sqltrace/tb_sqltrc_29659_103_1383332.trc
output file name : /sdiske/ps1/tbProfiler230217/log/1763430794_tbprof.outfile
sort option : default
aggregate : yes
sys : no
print : all
=================================================================
count: number of times the procedure was executed
cpu: cpu time(seconds)
this is not quite accurate due to threaded architecture
elapsed: elapsed time(seconds)
disk: number of physical reads from disk
query: number of blocks for consistent read
current: number of blocks in current mode
rows: number of rows processed
u_rows: original number of rows before filter was applied.
=================================================================
.... 생략 ....
vi 종료
-----------------------------
- file name : /sdiske/ps1/tbProfiler230217/log/1763430794_tbprof.outfile
-----------------------------
tbprof out file remove (y or n) ? y
- tr 수행 시 query 입력으로 수행 되었던 trc 파일을 tbprof 유틸리티로 분석 진행
- progress (100%) : 1초 후 tbprof outfile을 vi로 오픈 합니다.
- tbprof outfile 분석을 완료한 후 vi 명령 모드 :q 종료
- tbprof outfile 삭제 여부 확인
tbProifiler mode menu "q"
###############################
# tbProfiler mode menu
###############################
- tbProfiler : re
- tbprof : tr
- quit : q
-----------------------------
other key retry.
-----------------------------
press key : q
###############################
# tbProfiler mode stop
###############################
....exit
- tbProfiler.sh 쉘 스크립트를 통한 Query 사용 또는 tbProf outfile 분석이 완료 될 시 "q"를 통해 종료
tbProfiler.sh 오류
tbProfiler.sh 쉘 스크립트 관련 오류 메시지를 안내합니다.
tbProfiler.sh 쉘 스크립트 오류 메시지
# TB_SID에 해당하는 tbsvr이 기동 되어 있지 않은 경우 ERROR : Please check the tbsvr process. # TB_SID 환경 변수가 지정되지 않는 경우 발생 ERROR : TB_SID variable is empty. # tbProfiler.sh TBSQL_USER 파라미터가 설정되지 않은 경우 발생 ERROR : TBSQL_USER variable is empty. # tbProfiler.sh TBSQL_PASSWORD 파라미터가 설정되지 않은 경우 발생 ERROR : TBSQL_PASSWORD variable is empty. # tbProfiler.sh TB_SQLPATH 파라미터가 설정되지 않은 경우 발생 ERROR : TB_SQLPATH variable is empty. # tbProfiler.sh TB_SQLPATH 경로가 존재 하지 않은 경우 발생 ERROR : TB_SQLPATH path dose not exist. # tbProfiler.sh SQL_TRACE_FILE_PATH 파라미터가 설정되지 않은 경우 발생 ERROR : SQL_TRACE_FILE_PATH variable is empty. # tbProfiler.sh SQL_TRACE_FILE_PATH 경로가 존재 하지 않은 경우 발생 ERROR : SQL_TRACE_FILE_PATH path dose not exist.
tbProfiler.sh 플러그인
tbSQL에서 ↑ 방향키로 이전에 실행 했던 Query문을 수행하고 싶은 경우 rlwrap 유틸리티를 설치하여 사용 하 면 좀 더 편리하게 Query 수행을 할 수 있습니다.
rlwrap 플러그인
yum을 통한 설치 방법 root# yum install -y epel-release root# yum install -y rlwrap 위 방식으로 설치가 진행 되지 않는 경우 하기 명령을 통해 설치 할 수 있습니다. rpm 다운로드 및 yum 설치 root# wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/r/rlwrap-0.45.2-2.el7.x86_64.rpm root# rpm -Uvh rlwrap-0.45.2-2.el7.x86_64.rpm root# yum install -y perl perl-Data-Dumper perl-File-Slurp python3 rlwrap 정상 설치가 안되어 tbProfiler.sh 오류가 발생하는 경우 tbProfiler.sh 쉘 스크립트 내 rlwrap_vaild_check=Y 값을 N으로 수정하여 사용하시기 바랍니다.
- 설치가 정상적으로 이루어지면 tbProfiller.sh 수행 시 자동으로 rlwrap tbsql로 수행되어 방향키를 통해 이전 수행했던 query를 불러 올 수 있습니다.