안녕하세요? 쓸만한게없네 윤선식입니다.

 

이전 아티클에서 “Database Engine Tuning Advisor”에 대한 소개를 했는데요, 이후 작업에 대해 설명하려고 합니다.

http://www.sqler.com/384455

 

이 DTA 참 좋긴 한데, 한 가지 문제가 있습니다. 바로 MSDB에 모든 기록이 남는다는 것이죠.

 

1.     다음과 같은 후유증이 있습니다.

가.   MSDB DTA 관련 테이블이 그대로 존재합니다. 특히 DTA_tuninglog 테이블등의 Row수는 튜닝대상 쿼리가 많으면 많을수록 사이즈가 클 수밖에 없습니다.

 

1-1.jpg

 

 

나.   백업파일의 사이즈가 커집니다. 그림과 같이 갑자기 사이즈가 커진 것을 알 수 있습니다.

1-2.jpg

 

다.   그렇다면 MSDB의 사이즈는??? 사실 Job을 그리 많이 돌리는 Database가 아니기 때문에 이렇게까지 클 이유가 없죠.

1-3.jpg

 

2.     굳이 이를 보관할 필요가 있다면 별도의 DB에 보관하시고, 만약 보관의 필요가 없다면 다음 링크에 있는 명령어를 실행해 봅니다.

http://support.microsoft.com/kb/899634

 

/*

       Purpose of the Script

       This script cleans up objects created by DTA client on the target server

       (server being tuned). DTA creates support tables and stored procedures on the target server.

       The schema of the DTA tables and the DTA SP interfaces changed from Beta 2.

      

       When to use it

       If a Beta 2 DTA client was used to tune/evaluate against the target server then

       this script needs to be executed (against the target server) for later versions

       of DTA to function properly.

      

       Impact

       Previous session details are lost.

 

*/

go

use msdb

go

-- Drop DTA msdb Tables

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_indexcolumn') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_indexcolumn

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_querycolumn') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_querycolumn

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_querytable') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_querytable

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_tableview') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_tableview

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_querydatabase') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_querydatabase

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_queryindex') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_queryindex

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_column') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_column

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_index') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_index

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_table') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_table

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_query') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_query

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_partitionscheme') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_partitionscheme

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_partitionfunction') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_partitionfunction

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_tuninglog') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_tuninglog

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_reports_database') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_reports_database

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_progress') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_progress

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_output')and (type = 'U')and (uid = user_id('dbo'))))

       drop table dbo.DTA_output

if (exists (select * from msdb.dbo.sysobjects where (name = N'DTA_input') and (type = 'U') and (uid = user_id('dbo'))))

       drop table dbo.DTA_input

      

-- Drop DTA msdb SP's

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_check_permission' and type = 'P')

       drop procedure dbo.sp_DTA_check_permission

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_add_session' and type = 'P')

       drop procedure dbo.sp_DTA_add_session

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_delete_session' and type = 'P')

       drop procedure dbo.sp_DTA_delete_session

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_session_tuning_results' and type = 'P')

       drop procedure dbo.sp_DTA_get_session_tuning_results

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_set_interactivestatus' and type = 'P')

       drop procedure dbo.sp_DTA_set_interactivestatus

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_help_session' and type = 'P')

       drop procedure dbo.sp_DTA_help_session

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_update_session' and type = 'P')

       drop procedure dbo.sp_DTA_update_session

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_tuninglog' and type = 'P')

       drop procedure dbo.sp_DTA_get_tuninglog

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_usage_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_index_usage_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_usage_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_index_usage_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_database_access_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_database_access_helper_xml

if exists (select name from msdb.dbo.sysobjects where name = 'sp_DTA_database_access_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_database_access_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_table_access_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_table_access_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_table_access_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_table_access_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_column_access_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_column_access_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_column_access_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_column_access_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_costrange_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_query_costrange_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_costrange_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_query_costrange_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_cost_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_query_cost_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_cost_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_query_cost_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_event_weight_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_event_weight_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_event_weight_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_event_weight_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_detail_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_query_detail_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_detail_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_query_detail_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_indexrelations_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_query_indexrelations_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_query_indexrelations_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_query_indexrelations_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_current_detail_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_index_current_detail_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_recommended_detail_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_index_recommended_detail_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_detail_current_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_index_detail_current_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_index_detail_recommended_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_index_detail_recommended_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_view_table_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_view_table_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_view_table_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_view_table_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_wkld_analysis_helper_xml' and type = 'P')

       drop procedure dbo.sp_DTA_wkld_analysis_helper_xml

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_wkld_analysis_helper_relational' and type = 'P')

       drop procedure dbo.sp_DTA_wkld_analysis_helper_relational

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_session_report' and type = 'P')

       drop procedure dbo.sp_DTA_get_session_report

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_set_tuninglogtablename' and type = 'P')

       drop procedure dbo.sp_DTA_set_tuninglogtablename

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_tuningoptions' and type = 'P')

       drop procedure dbo.sp_DTA_get_tuningoptions

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_interactivestatus' and type = 'P')

       drop procedure dbo.sp_DTA_get_interactivestatus

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_progressinformation' and type = 'P')

       drop procedure dbo.sp_DTA_insert_progressinformation

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_set_progressinformation' and type = 'P')

       drop procedure dbo.sp_DTA_set_progressinformation

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_set_outputinformation' and type = 'P')

       drop procedure dbo.sp_DTA_set_outputinformation

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_database' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_database

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_partitionscheme' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_partitionscheme

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_partitionfunction' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_partitionfunction

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_column' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_column

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_tableview' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_tableview

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_query' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_query

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_index' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_index

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_table' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_table

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_queryindex' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_queryindex

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_indexcolumn' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_indexcolumn

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_querytable' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_querytable

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_querydatabase' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_querydatabase

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_reports_querycolumn' and type = 'P')

       drop procedure dbo.sp_DTA_insert_reports_querycolumn

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_insert_DTA_tuninglog' and type = 'P')

       drop procedure dbo.sp_DTA_insert_DTA_tuninglog

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_databasetableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_databasetableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_pftableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_pftableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_pstableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_pstableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_tableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_tableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_columntableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_columntableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_get_indexableids' and type = 'P')

       drop procedure dbo.sp_DTA_get_indexableids

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_update_tuninglog_errorfrequency' and type = 'P')

       drop procedure dbo.sp_DTA_update_tuninglog_errorfrequency

      

-- Drop unused SP's if they exist.           

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_columnaccesshelper' and type = 'P')

       drop procedure dbo.sp_DTA_columnaccesshelper

if exists (select name from msdb.dbo.sysobjects where name = 'sp_DTA_databaseaccesshelper' and type = 'P')

       drop procedure dbo.sp_DTA_databaseaccesshelper

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_indexusagehelper' and type = 'P')

       drop procedure dbo.sp_DTA_indexusagehelper

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_queryCRhelper' and type = 'P')

       drop procedure dbo.sp_DTA_queryCRhelper

if exists (select name from msdb.dbo.sysobjects      where name = 'sp_DTA_tableaccesshelper' and type = 'P')

       drop procedure dbo.sp_DTA_tableaccesshelper

 

3.     실행 후엔 어떤 변화가 있을까요?

가.   구문을 보면 아시겠지만, DTA 관련 테이블을 모두 DROP합니다. 하여 아무런 User Table도 남아있지 않게 됩니다.

 

 2-1.jpg

 

 

나.   MSDB 사이즈는 어떻게 될까요? 사용 가능한 공간이 924MB 892MB나 되네요.

2-2.jpg

 

다.   이제 Database Shrink(축소)를 해 보도록 합니다.

2-3.jpg

 

라.   짜잔다음과 같이 22.5MB로 사이즈가 줄게 됩니다.

2-4.jpg

 

DTA를 사용할 때 반드시 알아두어야 할 것 같네요.


안녕하세요? “쓸만한게없네 윤선식입니다.”

오늘은 데이터베이스 엔진 튜닝 관리자(Database Engine Tuning Advisor) 의 간단한 사용법에 대해 소개하고자 합니다.

데이터베이스 엔진 튜닝 관리자는 사용하는 쿼리와 테이블 등을 분석해서 통계 데이터와 인덱스 작성을 권장하도록 해 주는 아주아주 훌륭한 툴입니다.


데이터베이스 엔진 튜닝관리자를 사용하시려면 먼저 프로파일러 추적 파일 또는 Table을 만들어야 합니다.


이에 대해선, 강성욱님께서 작성하신 아티클을 참고해 주세요. ^^.

http://www.sqler.com/367698


, 추적파일이 있다는 가정 하에 진행하고, 2005 2008의 기능이 비슷하므로 2005 위주로 작성했습니다.


1.
프로그램 à Microsoft SQL Server 2005 à 성능 도구à 데이터베이스 엔진 튜닝 관리자

1.jpg

2. 추적파일을 실행하고 튜닝을 할 DB를 선택합니다.

2.jpg

 

 

3. 튜닝 관리자가 열리면 돋보기 버튼을 눌러서 위에서 만들어 둔 파일을 선택합니다.

3.jpg


4.
파일을 지정하고, 튜닝할 DB 또는 개체를 선택합니다.

          4.jpg

5. 튜닝옵션은 필요한 경우에 조합이 가능하지만, 여기서는 특별히 다루지 않을 예정입니다. 준비가 되면 분석 시작버튼을 누릅니다.

5.jpg

l 참고로 이 작업은 시간도 많이 걸리고 부하도 많이 주기 때문에 업무시간에 실서버에 진행하는 것은 별로 권장하지 않아요. ^^.

6. 진행이 완료되면, 예상향상률과 통계, 인덱스 등의 내용이 표시됩니다.

6.jpg

l 참고로, 예상향상률이 낮은 경우 굳이 인덱스 튜닝 관리자를 실행하지 않는 것이 낫다고 하는 의견이 많습니다. 아주 안 좋은 환경에서 튜닝 관리자로 분석하면 예상향상률이 200% 이상도 나온다고 하는군요. ^^

l 보고서를 먼저 한 번 검토해 보시는 것도 중요합니다. 보고서 내용에 따라 작업순서를 정하시는 것도 좋습니다.

7. 해당 내용을 바로 적용하지 말고 권장 구성 저장을 통해 SQL Script 파일로 만들어서 검토합니다.

7.jpg 

8. 권장구성 Script에서 이름은 임의대로 지정되고, Index Include 의 경우 다소 중복되는 부분들도 있을 수 있으므로 이름을 고쳐서 보기 좋게 해 두시는 것이 관리에 좋습니다.


1)
원본

CREATE NONCLUSTEREDINDEX [_dta_index_ESMINV2T_8_245575913__K17_3_4_20] ON [dbo].[ESMINV2T]

(

[BARCODE] ASC

)

INCLUDE ( [OUT_QTY],

[OUT_WT],

[WH_CODE]) WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

go


2)
수정본 샘플

CREATE NONCLUSTEREDINDEX IX_ESMINV2T_04 ON[dbo].[ESMINV2T]

(

[BARCODE] ASC

)

INCLUDE ( [OUT_QTY],

[OUT_WT],

[WH_CODE])

go


l
인덱스와 통계 적용 전의 실행계획과 이후의 실행계획을 비교해 보는 것도 흥미로운 일이 될 듯 합니다.

http://msdn.microsoft.com/ko-kr/library/ms166575.aspx: 자습서

+ Recent posts