. CBO 환경의 DB 를 운영하면서 절대 빼놓을수 없는 것 중 하나가 통계정보다.
개인적으로 느끼기엔 잘하면 본전인데 잘못하면 이거 대박 장애다.
직접 경험한 바로 프로젝트가 오픈하기전 개발에서 아무문제 없다가 실제 운영으로 이관하였고
다음날 아침 슈퍼돔 사양의 DB 가 뻗어벼렸다.
사후 원인분석 결과 통계정보가 개발기와 다름으로써 PLAN 이 변경되어 특정 SQL 하나만으로 슈퍼돔이 뻗어 버린것이다.
11G 에서는 통계정보가 얼마나 DBA 를 편하게 해줄지 몰라도 10G 에서의 통계정보는 항상 조심하자.
특정 SQL 하나가 슈퍼돔을 한순간에 뻗게 만들수도 있기 때문이다.
아래는 CBO 환경에서 DB 를 를 운영하면서 통계정보 관련 자주 사용하는 명령어들을 정리해봤다.
. 통계정보 생성
> exec dbms_stats.gather_table_stats(ownname=>'SCOTT', tabname=>'EMP', method_opt=> 'FOR ALL COLUMNS', cascade=>true , degree=>8, granularity=>'ALL'); |
. 통계정보 삭제
> exec dbms_stats.delete_table_stats('SCOTT','EMP') ; |
. 파티션 테이블 파티션 통계정보 삭제
> exec dbms_stats.delete_table_stats(ownname=> 'SCOTT',tabname=>'EMP_PART' ,partname=>'P_200812'); |
. 통계정보 백업 테이블 생성
> exec dbms_stats.create_stat_table(ownname=>'SYSTEM',stattab=>'STATS_BACKUP',tblspace=>'USERS'); |
. 통계정보 EXPORT
> exec dbms_stats.export_table_stats (OWNNAME=>'SCOTT', TABNAME=>'EMP', STATTAB=> 'STATS_BACKUP', STATID=> 'STATS_BACKUP',STATOWN=>'SYSTEM', cascade=>true); |
. 통계정보 IMPORT
> exec dbms_stats.import_table_stats (OWNNAME=>'SCOTT', TABNAME=>'EMP', STATTAB=> 'STATS_BACKUP', STATID=> 'STATS_BACKUP',STATOWN=>'SYSTEM', cascade=>true); |
. 테이블 통계정보 확인
> select owner, table_name, num_rows, last_analyzed from dba_tables
where table_name='EMP';
OWNER TABLE_NAME NUM_ROWS LAST_ANALYZED
------------------------------ ------------------------------ ----------- -------------------
SCOTT EMP 246 2008/12/11 00:16:00 |
. 인덱스 통계정보 확인
> SELECT owner, index_name, num_rows, last_analyzed from dba_indexes
where index_name='RM_RMNG_CMMN_CD_DTL_PK';
OWNER INDEX_NAME NUM_ROWS LAST_ANALYZED
------------------------------ ------------------------------ ----------- -------------------
CBADM RM_RMNG_CMMN_CD_DTL_PK 246 2008/12/11 00:16:02 |
. 파티션 테이블 통계정보 확인
> select table_owner, table_name, partition_name, num_rows, last_analyzed
from dba_tab_partitions where table_owner = 'SCOTT' and table_name = 'EMP_PART'
order by partition_position;
TABLE_OWNER TABLE_NAME PARTITION_NAME NUM_ROWS LAST_ANALYZED
------------------------------------------- ------------ ----------- ---------
SCOTT EMP_PART P_200801 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200802 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200803 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200804 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200805 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200806 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200807 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200808 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200809 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200810 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200811 1244703 2007/12/08 09:03:25
SCOTT EMP_PART P_200812 1244703 2007/12/08 09:03:25
|
. 파티션 인덱스 통계정보 확인
> select index_owner, index_name, partition_name, num_rows, last_analyzed
from dba_ind_partitions
where index_name in (select index_name
from dba_indexes
where table_owner = 'SCOTT'
and table_name = 'EMP_PART'
and partitioned = 'YES')
order by index_name, partition_position;
INDEX_OWNER INDEX_NAME PARTITION_NAME NUM_ROWS LAST_ANALYZED
------------------------------------------- ------------ ----------- ---------
SCOTT EMP_PART_IDX P_200801 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200802 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200803 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200804 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200805 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200806 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200807 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200808 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200809 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200810 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200811 1244703 2007/12/08 09:03:25
SCOTT EMP_PART_IDX P_200812 1244703 2007/12/08 09:03:25
|
. 파티션 테이블 통계정보 UNLOCK
> exec dbms_stats.unlock_table_stats('SCOTT','PART_EMP');
|
. 파티션 테이블 통계정보 LOCK 확인
> select owner, table_NAME, stattype_locked from dba_tab_statistics where table_name='PART_EMP' ;
OWNER TABLE_NAME STATT
------------------------------ ------------------------------ -----
SCOTT EMP_PART ALL
|
. 파티션 인덱스 통계정보 LOCK 확인
> select owner, index_NAME, stattype_locked from dba_ind_statistics
where index_name='PART_EMP_IDX';
OWNER INDEX_NAME STATT
------------------------------ ------------------------------ ---------------
SCOTT EMP_PART_IDX ALL
|