DB2 대략 설명 ~

2008. 11. 8. 17:24Database



1. DB2에서는 데이터베이스 외부에 있는 사용자 정보를 이용합니다.
   오라클과는 달리 데이타베이스내에 별도의 사용자를 생성할 필요가 없습니다.
  
2. 인스턴스 및 인스턴스 내에 존재하는 데이터베이스를 제어하는 sysadm, sysctrl, sysmaint, sysmon권한이 존재합니다.
3. 인스턴스 생성시 인스턴스 소유자인 사용자 및 동일 그룹에 속하는 사용자에게 sysadm이 부여되며
   database manager configuration 파일을 수정하여 sysadm,sysctrl,sysmaint 권한을 부여할 수 있습니다.
4. sysadm, sysctrl,sysmaint는 모두 인스턴스 시작과 중지를 수행할 수 있습니다.
5. Sysadm > sysctrk > sysmain 순으로 권한이 높습니다.
6. dbadm이라는 특권을 통해 데이터베이스에 속하는 여러가지 특권을 부여받을 수 있습니다.
7. 권한/특권 조회 방법
- sysibmadm.privileges
- sysibmadm.authorizationids
- sysibmadm.objecttowners
- syscat.dbauth
- syscat.tabauth
- syscat.colauth
- syscat.indexauth
- syscat.schemaauth
- syscat.sequenceauth
8. 예제
db2=>  select * from syscat.tabauth where tabname ='customer'
db2=> select * from sysibmadm.privileges where authid='john'

9."set role" 명령어를 이용하여 현재 접속한 사용자가 특정 role에 대한 권항이 있는지 확인합니다.
예> db2 => set role editor

9. 예제
db2=> create role editor
db2=> grant select on table test.t1 to role editor
db2=> grant editor to amj;
db2=> select * from sysibmadm.privileges
      where authid='editot';
db2=> select * from syscat.tabauth
      where grantee='editor'
db2=> revoke role editor from amj
  
=======================================================================
unit 10 데이터 이동 방법 비교   
=======================================================================
1. 데이타 이동 방법 비교
- import/export 툴을 이용한 데이터이동
- backup/ restore를 이용한 데이터 이동
- load 유틸리티를 이용한 데이터 이동
- 복제 솔루션을 이용한 데이타 이동
- relocatedb를 이용한 데이타베이스 이동.
 

2. load : 대용량 데이타를 새 테이블 또는 기존 테이블로 효율적으로 이동 가능
3. db2move : import/export 옵션과 함께 사용할 경우 db2 데이타베이스간에 대량의 테이블을 편리하게
     이동할 수 있습니다.
4. import: 외부 파일로부터 데이타를 읽어 테이블,뷰,닉네임에 삽입하고자 하는 경우 사용됩니다.
5. export: 데이타베이스로부터 데이타를 다양한 형태의 파일로 추출해 내고자 할 경우 사용됩니다.
6. admin_copy_schema: 당일 스키마내의 모든 오브젝트의 복사본을 생성하여 새로운 스키마에 속하는
   오브젝트로 재생성할 수 있습니다. copy옵션을 이용하여 데이타와 함께 복사할 것인지 아닐지를
   지정할 수 있습니다.    
7. redirect, generate script옵션과 함께 사용된 restore
   :기존 백업 이미지로부터 스크립트를 이요하여 한 시스템에서 다른 시스템으로 전체 데이터베이스를 복사할
     경우 사용됩니다.
    
8.db2relocatedb 명령어: 데이터베이스 이름의 재정의, 데이터베이스 위치 변경, 데이터베이스의 일부분을 같은 시스템또는
다른 시스템에 위치하고자 할 경우 사용합니다.
9. split mirror: 복제본, standby 또는 백업 데이타베이스를 생성하는데 사용됩니다.
      
10. export/ import 유틸리티 비교
- 오라클과 db2에서 데이터 이도에 가장 많이 사용되는 export/import 유틸리티를 비교합니다.
- 데이터를 이기종간에 이동하기 위한 가장 간편한 방법입니다.
/* 팁      
아니면 export to t1.ixf of ixf select ~
/야옹/ 조는 냥이 zZ 님의 말 :
import from t1.ixf of ixf replace_create into tabname

==> 실습
[inst95@localhost ~]$ db2 "export to emp_1.ixf of ixf select * from act"
SQL3104N  The Export utility is beginning to export data to file "emp_1.ixf".
SQL3105N  The Export utility has finished exporting "18" rows.

Number of rows exported: 18
[inst95@localhost ~]$ db2 "import from emp_1.ixf insert into emp_1"
SQL0104N  An unexpected token "insert" was found following "<identifier>". 
Expected tokens may include:  "OF".  SQLSTATE=42601
[inst95@localhost ~]$ db2 "import from emp_1.ixf insert into act_1"
SQL0104N  An unexpected token "insert" was found following "<identifier>". 
Expected tokens may include:  "OF".  SQLSTATE=42601
[inst95@localhost ~]$ db2 "import from emp_1.ixf insert into inst95.act_1"
SQL0104N  An unexpected token "insert" was found following "<identifier>". 
Expected tokens may include:  "OF".  SQLSTATE=42601
[inst95@localhost ~]$ db2 "import from emp_1.ixf of ixf insert into inst95.act_1"
SQL3150N  The H record in the PC/IXF file has product "DB2    02.00", date
"20081024", and time "122153".
SQL3153N  The T record in the PC/IXF file has name "emp_1.ixf", qualifier "",
and source "            ".
SQL3109N  The utility is beginning to load data from file "emp_1.ixf".
SQL3110N  The utility has completed processing.  "18" rows were read from the
input file.
SQL3221W  ...Begin COMMIT WORK. Input Record Count = "18".
SQL3222W  ...COMMIT of any database changes was successful.
SQL3149N  "18" rows were processed from the input file.  "18" rows were
successfully inserted into the table.  "0" rows were rejected.

Number of rows read         = 18
Number of rows skipped      = 0
Number of rows inserted     = 18
Number of rows updated      = 0
Number of rows rejected     = 0
Number of rows committed    = 18
[inst95@localhost ~]$

11. db2 export /import 비교
-  ddl 파일 및 통계 자료를 추출해 냅니다.
[inst95@localhost ~]$ db2look -d sample -a -e -l -x -m -f
12. load 예제1
[inst95@localhost ~]$ db2 "select count(*) from act_1"
1         
-----------
         18
  1 record(s) selected.
[inst95@localhost ~]$ db2 "load from /dev/null of del replace into act_1"
SQL3501W  The table space(s) in which the table resides will not be placed in
backup pending state since forward recovery is disabled for the database.
SQL3109N  The utility is beginning to load data from file "/dev/null".
SQL3500W  The utility is beginning the "LOAD" phase at time "2008-10-24
12:40:18.566904".
SQL3519W  Begin Load Consistency Point. Input record count = "0".
SQL3520W  Load Consistency Point was successful.
SQL3110N  The utility has completed processing.  "0" rows were read from the
input file.
SQL3519W  Begin Load Consistency Point. Input record count = "0".
SQL3520W  Load Consistency Point was successful.
SQL3515W  The utility has finished the "LOAD" phase at time "2008-10-24
12:40:18.645476".

Number of rows read         = 0
Number of rows skipped      = 0
Number of rows loaded       = 0
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 0
[inst95@localhost ~]$ db2 "select count(*) from act_1"
1         
-----------
          0
  1 record(s) selected.
13. DB2 load 유틸리티
- import와 유사한 툴로 파일로부터 대량의 데이타를 기존의 테이블에 고속으로 저장하는 유틸리티입니다.
load 명령어와 set integry 명령어가 사용됩니다.
- 작업방법
1) load : 입력파일의 데이타를 테이블 스페이스 컨테이너로 직접복사합니다.
2) build: 수집한 인덱스 정보를 이용하여 기존 인덱스를 갱신하거나 재생성합니다.
3) delete: 고유 인덱스를 위반한 데이타를 점검하여 미리 정의된 예외 테이블로 입력합니다.
- load query 명령어를 이용하여 테이블의 상태를 확인합니다.
-load 명령어가 완려되면 목표 테이블은 점검 보류상태가 됩니다.
 예외 테이블을 이용하여 set integrety 문으로 점검 보류 상태를 해지합니다.
 
 [inst95@localhost ~]$ db2 load query table act summaryonly
Tablestate:
  Normal
[inst95@localhost ~]$

[inst95@localhost ~]$ db2 "load from emp_1.ixf of ixf insert into act_1"
SQL3501W  The table space(s) in which the table resides will not be placed in
backup pending state since forward recovery is disabled for the database.
SQL3109N  The utility is beginning to load data from file
"/home/inst95/emp_1.ixf".
SQL3500W  The utility is beginning the "LOAD" phase at time "2008-10-24
13:00:00.387066".
SQL3150N  The H record in the PC/IXF file has product "DB2    02.00", date
"20081024", and time "122153".
SQL3153N  The T record in the PC/IXF file has name "emp_1.ixf", qualifier "",
and source "            ".
SQL3519W  Begin Load Consistency Point. Input record count = "0".
SQL3520W  Load Consistency Point was successful.
SQL3110N  The utility has completed processing.  "18" rows were read from the
input file.
SQL3519W  Begin Load Consistency Point. Input record count = "18".
SQL3520W  Load Consistency Point was successful.
SQL3515W  The utility has finished the "LOAD" phase at time "2008-10-24
13:00:00.437848".

Number of rows read         = 18
Number of rows skipped      = 0
Number of rows loaded       = 18
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 18
[inst95@localhost ~]$
14. db2move 유틸리티
- db2move 유틸리티를 이용하여 테이블 별, 테이블 스페이스 별, 스키마별, 또는
전체 데이타베이스에 대한 import, export, load작업을 수행할 수 있습니다.
- 구문
 >db2move <dbname> export     -tc <테이블 생성자>
                   import     -tn <테이블 이름>
                   load       -sn <스키마 이름>
                   copy        -ts <테이블 스페이스 이름>
- 필요 파일 및 자동 생성되는 파일
.export시 : input 파일은 필요치 않으며 db2move list, tabnnn.ixf,tabnnn.msg,tabnnn.yyy 파일이
자동으로 생성됩니다.
.import시 : input 파일로 db2move.lst 파일, tabnnn.ixf, tabnnn.msg, tabnnnc.yyy 파일이
 필요하며 import.out 파일과 tabnnn.msg 파일이 자동 생성됩니다.
 
15. 예문
>db2move sample export 

[inst95@localhost ~]$ db2move sample export
Application code page not determined, using ANSI codepage 970
*****  DB2MOVE  *****
Action:  EXPORT
Start time:  Fri Oct 24 13:22:17 2008

Connecting to database SAMPLE ... successful!  Server : DB2 Common Server V9.1.3
Binding package automatically ... /home/inst95/sqllib/bnd/db2common.bnd ... successful!
Binding package automatically ... /home/inst95/sqllib/bnd/db2move.bnd ... successful!
EXPORT:     18 rows from table "INST95  "."ACT"
EXPORT:     18 rows from table "INST95  "."ACT_1"
EXPORT:      0 rows from table "INST95  "."BONUS"
EXPORT:      5 rows from table "INST95  "."CL_SCHED"
EXPORT:     14 rows from table "INST95  "."DEPARTMENT"
EXPORT:      8 rows from table "INST95  "."EMP_PHOTO"
EXPORT:      8 rows from table "INST95  "."EMP_RESUME"
EXPORT:     42 rows from table "INST95  "."EMPLOYEE"
EXPORT:  10000 rows from table "INST95  "."EMPMDC"
EXPORT:     73 rows from table "INST95  "."EMPPROJACT"
EXPORT:    143 rows from table "SYSTOOLS"."HMON_ATM_INFO"
EXPORT:      0 rows from table "SYSTOOLS"."HMON_COLLECTION"
EXPORT:      3 rows from table "INST95  "."IN_TRAY"
EXPORT:      8 rows from table "INST95  "."ORG"
EXPORT:      5 rows from table "SYSTOOLS"."POLICY"
EXPORT:     65 rows from table "INST95  "."PROJACT"
EXPORT:     20 rows from table "INST95  "."PROJECT"
EXPORT:      3 rows from table "QUEST   "."QCOBJLIST_REPO045"
EXPORT:     12 rows from table "QUEST   "."QCOBJLIST_STMT045"
EXPORT:      0 rows from table "QUEST   "."QCREPORT_DETAIL045"
EXPORT:      0 rows from table "QUEST   "."QCREPORT_REPO045"
EXPORT:     41 rows from table "INST95  "."SALES"
EXPORT:      0 rows from table "SCOTT   "."SALGRADE"
EXPORT:      0 rows from table "INST95  "."SCOTT_BONUS"
EXPORT:      4 rows from table "INST95  "."SCOTT_DEPT"
EXPORT:     14 rows from table "INST95  "."SCOTT_EMP"
EXPORT:      0 rows from table "INST95  "."SCOTT_SALGRADE"
EXPORT:      1 rows from table "QUEST   "."SM_DB_IDS"
EXPORT:      5 rows from table "QUEST   "."SM_IDS"
EXPORT:      0 rows from table "QUEST   "."SM_INDEX_HISTORY"
EXPORT:      0 rows from table "QUEST   "."SM_INDEX_IDS"
EXPORT:      1 rows from table "QUEST   "."SM_INSTANCE_IDS"
EXPORT:      1 rows from table "QUEST   "."SM_MACHINE_IDS"
EXPORT:    143 rows from table "QUEST   "."SM_TABLE_HISTORY"
EXPORT:    143 rows from table "QUEST   "."SM_TABLE_IDS"
EXPORT:      0 rows from table "QUEST   "."SM_TABLESPACE_HISTORY"
EXPORT:      4 rows from table "QUEST   "."SM_TABLESPACE_IDS"
EXPORT:     35 rows from table "INST95  "."STAFF"
Disconnecting from database ... successful!
End time:  Fri Oct 24 13:22:23 2008
[inst95@localhost ~]$
                  
16. db2move를 이용한 import 예
예제> db2move sample export -io replace -uinst95 -p ***
==> sample 데이타베이스의 모든 테이블을 replace 모드로 import합니다.
예제2> db2move dbsrc copy -sn amj -co target_db dbtgt user inst95 using ***
==> source 데이터베이스의 amj 스키마를 target 데이타베이스로 복사합니다.
****
실습용 데이타베이스 만들기

CATALOG DATABASE sample2
    AS sample2
    AT NODE NDE498C3
     AUTHENTICATION SERVER;
=====================================?
오늘의 실습
1. 서버에서 db 생성하면...
>db2 create database sample2

2. 클라이언트에서 해줘야 할 일...
>
> db2 list node directory
>db2 catalog db sample2 as sam2 at node sample2
>db2 connect to sam2 user inst95 using inst95
=====================================?
다시 실습해 봅시다.
[서버]
[inst95@localhost ~]$ db2 create database sample3
DB20000I  The CREATE DATABASE command completed successfully.
[inst95@localhost ~]$
[클라이언트]
C:\Users\mini>db2 catalog db sample3 as sam3 at node sample2
DB20000I  CATALOG DATABASE 명령이 완료되었습니다.
DB21056W  디렉토리 변경사항은 디렉토리 캐시를 새로 고쳐야 적용됩니다.
 
======================================>
다음과제
db2 <-> db2.인스턴스.db명  연결 synonym 으로 연결한다.
오라클과 연결시 별도의 제품 군이 있다.
********************************************************
init 11: 백업 및 복구 비교
********************************************************
1. db2, circular 순환로깅 :차 전체 데이터베이스 백업 및 복구만 가능합니다.
2. Archive 로깅: 변경된 트랜잭션의 이력 데이타를 저장하며 archived 로그를 위해
                  저장 공간이 계속적으로 필요합니다.
                 
3. DB2 로깅 전환 및 확인 방법
- 로깅모드 설정방법: update db cfg for <db명> using logarchmeth1 disk:c:\aech_log
- 로그파일 위치 지정: update db cfg for <db명> using newlogpath /log
- 로그파일의 이름 규칙: 로그파일의 이름은 s000000.log 등 자동으로 순
- 로그모드방법 : database configuration 파라미터인 logarchmeth1이 off가 아닌지 확인합니다.
  > get db cfg for <db명> |grep logarchmeth1
 
4. 로그파일 및 아카이빙 비교
- database configuration 파라미터인 logmirrorpath를 지정하여 log 파일의 복사본을 저장할 파일 시스템을
   지정합니다.
 > update db cfg for <db명> using mirrorlogpath /mirrorlog
 
 *참고> 로깅모드를 변경한 후에는 데이터베이스가 backup pending 상태가 됩니다.
   backup pending이 되면 backup을 수행하여 backup pending에서 빠져나오도록 합니다.
5. 로깅모드 변경
                       

[inst95@localhost ~]$ db2 get db cfg for sample|grep "LOG"
 Catalog cache size (4KB)              (CATALOGCACHE_SZ) = (MAXAPPLS*4)
 Log buffer size (4KB)                        (LOGBUFSZ) = 8
 Log file size (4KB)                         (LOGFILSIZ) = 1000
 Number of primary log files                (LOGPRIMARY) = 3
 Number of secondary log files               (LOGSECOND) = 2
 Changed path to log files                  (NEWLOGPATH) =
 Path to log files                                       = /home/inst95/inst95/NODE0000/SQL00001/SQLOGDIR/
 Overflow log path                     (OVERFLOWLOGPATH) =
 Mirror log path                         (MIRRORLOGPATH) =
 Block log on disk full                (BLK_LOG_DSK_FUL) = NO
 Percent max primary log space by transaction  (MAX_LOG) = 0
 Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0
 Log retain for recovery enabled             (LOGRETAIN) = OFF
 First log archive method                 (LOGARCHMETH1) = OFF
 Options for logarchmeth1                  (LOGARCHOPT1) =
 Second log archive method                (LOGARCHMETH2) = OFF
 Options for logarchmeth2                  (LOGARCHOPT2) =
 Log pages during index build            (LOGINDEXBUILD) = OFF
[inst95@localhost ~]$

데이터베이스 재활성하면 sql1116n 에러가 발생합니다.
>db2 activate db sample
...
전체 fullback
>db2 backup db sample
>db2 activate db sam,ple
>dir db2_logs
>dir arch_log
 
> 백업여부 확인
>db2 deactive db sam
>db2 list history backup all for db sample
db2 update db cfg for sample using NEWLOGPATH /home/inst95/db2_logs
db2 update db cfg for sample using LOGARCHMETH1 DISK:/home/inst95/arch_log

[inst95@localhost ~]$ db2 update db cfg for sample using NEWLOGPATH /home/inst95/db2_logs
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
[inst95@localhost ~]$ db2 update db cfg for sample using LOGARCHMETH DISK:/home/inst95/arch_log
SQL0104N  An unexpected token "LOGARCHMETH" was found following "USING". 
Expected tokens may include:  "ADSM_MGMTCLASS".  SQLSTATE=42601
[inst95@localhost ~]$ db2 update db cfg for sample using LOGARCHMETH1 DISK:/home/inst95/arch_log
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
[inst95@localhost ~]$
 
[inst95@localhost ~]$ db2 update db cfg for sample using NEWLOGPATH /home/inst95/db2_logs
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
[inst95@localhost ~]$ db2 update db cfg for sample using LOGARCHMETH DISK:/home/inst95/arch_log
SQL0104N  An unexpected token "LOGARCHMETH" was found following "USING". 
Expected tokens may include:  "ADSM_MGMTCLASS".  SQLSTATE=42601
[inst95@localhost ~]$ db2 update db cfg for sample using LOGARCHMETH1 DISK:/home/inst95/arch_log
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
[inst95@localhost ~]$
[inst95@localhost ~]$
[inst95@localhost ~]$ db2 force applications all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.
[inst95@localhost ~]$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
[inst95@localhost ~]$ db2 deactivate db sample
SQL1496W  Deactivate database is successful, but the database was not
activated.
[inst95@localhost ~]$ db2 activate db sample
SQL1116N  A connection to or activation of database "SAMPLE" cannot be made
because of BACKUP PENDING.  SQLSTATE=57019
[inst95@localhost ~]$ db2 backup db sample
Backup successful. The timestamp for this backup image is : 20081024152111
[inst95@localhost ~]$ db2 activate db sample
DB20000I  The ACTIVATE DATABASE command completed successfully.
[inst95@localhost ~]$

[inst95@localhost SAMPLE]$ db2 get db cfg for sample
       Database Configuration for Database sample
 Database configuration release level                    = 0x0b00
 Database release level                                  = 0x0b00
 Database territory                                      = KR
 Database code page                                      = 970
 Database code set                                       = IBM-eucKR
 ...
 First log archive method                 (LOGARCHMETH1) = DISK:/home/inst95/arch_log/
 
 아카이브 모드로 변경했으면 이제  백업받는 방법
 
 
 [inst95@localhost SAMPLE]$ db2 list history backup all for sample
                    List History File for sample
Number of matching file entries = 1

 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log  Backup ID
 -- --- ------------------ ---- --- ------------ ------------ --------------
  B  D  20081024152111001   F    D  S0000000.LOG S0000000.LOG 
 ----------------------------------------------------------------------------
  Contains 4 tablespace(s):
  00001 SYSCATSPACE                                                          
  00002 USERSPACE1                                                           
  00003 IBMDB2SAMPLEREL                                                      
  00004 SYSTOOLSPACE                                                         
 ----------------------------------------------------------------------------
    Comment: DB2 BACKUP SAMPLE OFFLINE                                       
 Start Time: 20081024152111
   End Time: 20081024152119
     Status: A
 ----------------------------------------------------------------------------
  EID: 7 Location: /home/inst95
[inst95@localhost SAMPLE]$
[inst95@localhost ~]$ db2 backup db sample to /homr/inst95/backup
SQL1035N  The database is currently in use.  SQLSTATE=57019
[inst95@localhost ~]$
[inst95@localhost ~]$ db2 backup db sample online
Backup successful. The timestamp for this backup image is : 20081024152748

ackup successful. The timestamp for this backup image is : 20081024152748
[inst95@localhost ~]$ find /home/inst95 -name 20081024*
[inst95@localhost ~]$ pwd
/home/inst95
[inst95@localhost ~]$ ls -al
합계 137224
drwxr-xr-x  10 inst95 db2igrp     4096 10월 24 15:27 .
drwxr-xr-x   7 root   root        4096 10월 22 08:53 ..
-rw-r--r--   1 inst95 db2igrp     1335 10월 22 08:53 .Xresources
-rw-------   1 inst95 db2igrp      888 10월 24 10:17 .bash_history
-rw-r--r--   1 inst95 db2igrp       24 10월 22 08:53 .bash_logout
-rw-r--r--   1 inst95 db2igrp      191 10월 22 08:53 .bash_profile
-rw-r--r--   1 inst95 db2igrp      270 10월 22 08:56 .bashrc
-rw-r--r--   1 inst95 db2igrp     5619 10월 22 08:53 .canna
-rw-r--r--   1 inst95 db2igrp      383 10월 22 08:53 .emacs
-rw-r--r--   1 inst95 db2igrp       57 10월 22 08:53 .gtkrc-2.0
drwxr-xr-x   4 inst95 db2igrp     4096 10월 22 08:53 .kde
drwxr-xr-x   2 inst95 db2igrp     4096 10월 22 08:53 .qt
-rw-r--r--   1 inst95 db2igrp      658 10월 22 08:53 .zshrc
drwxr-xr-x   3 inst95 db2igrp     4096 10월 22 08:53 Desktop
-rw-r--r--   1 inst95 db2igrp     2531 10월 24 13:22 EXPORT.out
-rw-r-----   1 inst95 db2igrp 70881280 10월 24 15:21 SAMPLE.0.inst95.NODE0000.CATN0000.20081024152111.001
-rw-r-----   1 inst95 db2igrp 68976640 10월 24 15:27 SAMPLE.0.inst95.NODE0000.CATN0000.20081024152748.001
drwxr-xr-x   3 inst95 db2igrp     4096 10월 24 15:20 arch_log
drwxr-xr-x   2 inst95 db2igrp     4096 10월 24 15:26 backup
drwxr-xr-x   3 inst95 db2igrp     4096 10월 24 15:17 db2_logs
-rw-r--r--   1 inst95 db2igrp     1750 10월 24 13:22 db2move.lst
drwxrwxr-x   3 inst95 db2igrp     4096 10월 22 08:56 inst95
drwxrwsr-t  18 inst95 db2igrp     4096 10월 24 13:46 sqllib
-rw-r--r--   1 inst95 db2igrp     6752 10월 24 13:22 tab15a.001.lob
-rw-r--r--   1 inst95 db2igrp   387034 10월 24 13:22 tab6a.001.lob
-rw-r--r--   1 inst95 db2igrp    14787 10월 24 13:22 tab7a.001.lob
[inst95@localhost ~]$
 
Incremental 백업절차
1). 아카이브 로깅 상태에서만 지원되므로 logarchment1값을 off가 아닌
다른 값으로 설정합니다.
db2> update db cfg for db명 using logarchmeth1 disk:경로명
2)Trackmod 데이터베이스 구성 변수의 값을 "on"으로 성정하여
마지막 백업 이후에 변경된 데이터를 추정할 수 있도록 합니다.
db2> update db cfg foe <db명> using trackmod on
3) incremental, delte, online 등 다양한 옵션을 이용하여 최근의
 full 백업 또는 incremantal 백업 이후에 변경된 부분에 대해서
 백업 이미지를 생성합니다.
 
 db2> backup db <db명> incremental
 db2> backup db <db명> online incremental delta include logs
 *
 ==> 아카이브 모드인지 아닌지 확인해 봅시다 .
 
 
 [inst95@localhost ~]$ db2 get db cfg for sample |grep "LOGARCHMETH1"
 First log archive method                 (LOGARCHMETH1) = DISK:/home/inst95/arch_log/
[inst95@localhost ~]$
==> 백업 명령어를 이용하여 백업 수행 동시에 list utilities를 수행하여
백업 진행 상황을 체크합니다.
> db2 backup db sample
> db2 list utilities show detail

===> 자... 마지막... 갑시다. unit 12: 모니터링 비교

1. db2의 db2diag.log 파일
- db2diag 툴을 이용하여 db2diag.log 파일을 해석할 수 있으며 특정 정보를 추출하여 볼 수도 있습니다.
- diagraph 인스턴스 구성 변수에 의해 위치가 지정되며 default 위치는 <인스턴스홈디렉토리>/sqllib/db2dump 입니다.
2. db2trc 명령어를 이용하여 on/off합니다.
 - db2trc on -| 4m
 
 3. 성능 모니터링 뷰 및 유틸리티 비교
 - DB2 control center
 - db2 health center
 - 이벤트 분석기
 - 활동 모니터
 - 스냅샷 모니터 및 이벤트 모니터
 - sysib,ad,.xxx 의 테이블 정보
 - 스냅샷 모니터 및 이베니트 모니터
 
 4. db2pd 도구
 - db2pd 도구는 db2 메모리 세트의 빠르고 즉각적인 정보를 포함하는 문제점 판별도구입니다.
 
 5. DB2 스냅샷 모니터
 - 실시간 모니터링 툴로 스냅샷 함수, 스냅샷 API, 또는 스낸샷 명령어를 이용하에 데이터베이스의 활동 상황을
 모니터링 할 수 있습니다.
 
 
 6. 모니터 스위치를 켜면 현재 시점의 데이터베이스의 활동 상황을 모니터링 할 수 있습니다.
 
 
 7. 이벤트 모니터는 일정기간 동안 데이터베이스의 활동 내역에 대한 모니터링 정보를 수집하여
 파일또는 테이블에 저장하여 분석합니다.
 
 이벤트 모니터 => syscat.eventmonitors 테이블, syscat.events
 syscat.eventtables을 조회하여 이벤트 정보를 조회합니다.
 
 
 8. 이벤트 모니터 명령어
 db2=> create event monitor
 db2=> drop event monitor
 db2=> set event monitor
 db2=> flush event monitor
 
 9.  파일에다가 이벤트 로그 쌓아놓기
 [inst95@localhost ~]$ db2 "create event monitor event1 for deadlocks  write to file '/home/inst95/em_rep'"
DB20000I  The SQL command completed successfully.
[inst95@localhost ~]$

10. 테이블에다가 이벤트 로그 쌓아보기
db2=>< create tablespace evtbs managed by automatic storage
db2=> create event monitor t_evmon for tables write to table
      table (table evmon.Table_T_evmon, in evtbs,pctdeactivate 90)
     
11, 테이블 이벤트 모니터 생성 명령어에 대해 생소할 경우
db2evtbl 명령어를 이용하여 생성구문에 대해 다음과 같이 도움을 받을 수 있습니다.
보여주는 구문을 편집하여 이벤트 모니터를 생성하도록 합니다.
> db2evtbl -schema evmon -evm amj tables > cremon.ddl
> db2 -tvf cremon.ddl
12. 이벤트 모니터를 활성화 시킵니다.
db2> set event monitor t_evmon state=1
db2> set event monitor t_evmon state=0
13. 이벤트 모니터가 종료되면 불필요한 모니터와 테이블을 제거합니다.
db2> drop event monitor t_evmon
db2> drop table evmon.table_T_evmon
14. db2pd 사용예제
[inst95@localhost ~]$ db2pd -db sample -app -memblock
 db2pd -db sample -app -dyn
 
 
 15. db2 이벤트 모니터 예제
clp창을 하나 띄운 수 모니터 세션으로 사용합니다. 이 창에는 sample 데이터베이스에 연결하여
데이터베이스로 연결하는 사이에 발생하는 교착상태와 테이블 데이타를 로그하는 이벤트 모니터를 정의합니다.
 
 db2> db2 connect to sample
 db2> mkdir dimon
 db2> vi crevent.ddl
    create event monitor dlmon
       for tables, deadlocks with details
       write to file '/home/inst95/';
    set event monitor dlmon state 1;
   
db2> db2 -tvf crevent.ddl

결과조회
[inst95@localhost ~]$ cd dimon
[inst95@localhost dimon]$ ls -al
합계 16
drwxr-xr-x   2 inst95 db2igrp 4096 10월 24 17:15 .
drwxr-xr-x  12 inst95 db2igrp 4096 10월 24 17:15 ..
-rw-r--r--   1 inst95 db2igrp  261 10월 24 17:15 00000000.evt
-rw-r-----   1 inst95 db2igrp  300 10월 24 17:15 db2event.ctl
[inst95@localhost dimon]$