Sei sulla pagina 1di 25

2/23/2015

SQLTuningAdvisor

SQLTuningAdvisorinOracleSQLDeveloper3.0
Thistutorialcontainsthefollowingsections:
Purpose
TimetoComplete
Overview
SoftwareandHardwareRequirements
Prerequisites
CreatingaDatabaseConnection
ProvidingPrivilegesandRemovingtheexistingStatistics
ontheScottUser
RunningtheSQLTuningAdvisoronaSQLstatement
ImplementingSQLTuningAdvisorrecommendations
Summary

Purpose
ThistutorialshowsyouhowtousetheSQLTuningAdvisorfeatureinOracleSQLDeveloper3.0.

TimetoComplete
Approximately20minutes.

Overview
TheSQLTuningAdvisoranalyzeshighvolumeSQLstatementsandofferstuningrecommendations.Ittakesoneormore
SQLstatementsasaninputandinvokestheAutomaticTuningOptimizertoperformSQLtuningonthestatements.Itcan
runagainstanygivenSQLstatement.TheSQLTuningAdvisorprovidesadviceintheformofpreciseSQLactionsfor
tuningtheSQLstatementsalongwiththeirexpectedperformancebenefits.Therecommendationoradviceprovided
relatestothecollectionofstatisticsonobjects,creationofnewindexes,restructuringoftheSQLstatement,orcreationof
aSQLprofile.YoucanchoosetoaccepttherecommendationtocompletethetuningoftheSQLstatements.
OracleDatabasecanautomaticallytuneSQLstatementsbyidentifyingproblematicSQLstatementsandimplementing
tuningrecommendationsusingtheSQLTuningAdvisor.YoucanalsoruntheSQLTuningAdvisorselectivelyonasingle
orasetofSQLstatementsthathavebeenidentifiedasproblematic.
Inthistutorial,youlearnhowtorunandreviewtherecommendationsoftheSQLTuningAdvisor.
Note:TuningAdvisorispartoftheTuningPack,oneoftheOraclemanagementpacksandisavailableforpurchasewith
EnterpriseEdition.FormoreinformationseeTheOracleTechnologyNetworkortheonlinedocumentation.

SoftwareandHardwareRequirements
Thefollowingisalistofsoftwarerequirements:
OracleDatabase11gEnterpriseEditionwithaccesstotheTuningandDiagnosticmanagementpacksandwiththe
sampleschemainstalled.
OracleSQLDeveloper3.0.

Prerequisites
Beforestartingthistutorial,youshould:
1. InstallOracleSQLDeveloper3.0fromOTN.Followthereadmeinstructionshere.
2. InstallOracleDatabase11gwiththeSampleschema.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

1/25

2/23/2015

SQLTuningAdvisor

CreatingaDatabaseConnection
ThefirststeptomanagingdatabaseobjectsusingOracleSQLDeveloper3.0istocreateadatabaseconnection.
Performthefollowingstepstocreateadatabaseconnection:
Note:IfyoualreadyhavedatabaseconnectionsforSCOTTandSYSTEM,youdonotneedtoperformthefollowingsteps.
YoucanmovetoProvidingPrivilegestotheScottUsertopic.
1. IfyouhaveinstalledtheSQLDevelopericononyourdesktop,clicktheicontostartyourSQLDeveloperandmove
toStep4.Ifyoudonothavetheiconlocatedonyourdesktop,performthefollowingstepstocreateashortcutto
launchSQLDeveloper3.0fromyourdesktop.
OpenthedirectorywheretheSQLDeveloper3.0islocated,rightclicksqldeveloper.exe(onWindows)or
sqldeveloper.sh(onLinux)andselectSendto>Desktop(createshortcut).

2. Onthedesktop,youwillfindaniconnamedShortcuttosqldeveloper.exe.DoubleclicktheicontoopenSQL
Developer3.0.
Note:Torenameit,selecttheiconandthenpressF2andenteranewname.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

2/25

2/23/2015

SQLTuningAdvisor

3. YourOracleSQLDeveloperopensup.

4. IntheConnectionsnavigator,rightclickConnectionsandselectNewConnection.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

3/25

2/23/2015

SQLTuningAdvisor

5. TheNew/SelectDatabaseConnectiondialogopens.EntertheconnectiondetailsasfollowsandclickTest.
ConnectionName:system
Username:system
Password:<your_password>(SelectSavePassword)
Hostname:localhost
SID:<your_own_SID>

6. Checkforthestatusoftheconnectionontheleftbottomside(abovetheHelpbutton).ItshouldreadSuccess.
ClickSaveandthenclickConnect.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

4/25

2/23/2015

SQLTuningAdvisor

7. IntheConnectionsnavigator,tocreateanewconnectiontothescottschema,rightclickConnectionsandselect
NewConnection.

8. TheNew/SelectDatabaseConnectiondialogopens.EntertheconnectiondetailsasfollowsandclickTest.
ConnectionName:scott
Username:scott
Password:<your_password>(SelectSavePassword)
Hostname:localhost
SID:<your_own_SID>

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

5/25

2/23/2015

SQLTuningAdvisor

9. Checkforthestatusoftheconnectionontheleftbottomside(abovetheHelpbutton).ItshouldreadSuccess.
ClickSaveandthenclickConnect.

10. TheconnectionissavedandyoucanviewthetwonewlycreatedconnectionsintheConnectionslist.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

6/25

2/23/2015

SQLTuningAdvisor

ProvidingPrivilegesandRemovingtheexistingStatisticsontheScottUser
AuserrequirescertainprivilegestoruntheSQLTuningAdvisor.Also,inordertocollectandmanagestatisticsonthe
SCOTTschema,theexistingstatisticshavetobecleared.BelowarethestepstograntSQLTuningAdvisorprivilegesand
removetheexistingstatisticsonthescottuser.
1.

ClickSQLWorksheet

andselectsystemuser.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

7/25

2/23/2015

SQLTuningAdvisor

2. TograntprivilegestothescottusertoruntheSQLTuningAdvisor,enterthefollowinglinesofcode.ClickRun
Statement

grantadvisortoscott
grantadministersqltuningsettoscott

3. Theoutputforthestatementsisdisplayed.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

8/25

2/23/2015

SQLTuningAdvisor

4. TheOracledatabaseallowsyoutocollectstatisticsofmanydifferentkindsinordertoimproveperformance.To
illustratesomeofthefeaturestheSQLTuningAdvisoroffers,cleartheexistingstatisticsfromtheSCOTTschema.
Todeletetheschemastatistics,enterthefollowinglineofcode.
execDBMS_STATS.DELETE_SCHEMA_STATS('scott')
Selectthestatementandclick

RunStatement

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

9/25

2/23/2015

SQLTuningAdvisor

WiththeDBMS_STATSpackageyoucanviewandmodifyoptimizerstatisticsgatheredfordatabaseobjects.The
DELETE_SCHEMA_STATSproceduredeletesstatisticsforanentireschema.

5. Theoutputforthestatementappears.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

10/25

2/23/2015

SQLTuningAdvisor

RunningtheSQLTuningAdvisoronaSQLstatement
Inthistopic,youruntheSQLTuningAdvisoronaSQLstatement.FourtypesofanalysisareperformedbytheSQL
TuningAdvisorontheSQLstatement.
AlltherecommendationsaredisplayedintheOverview.Youcanalsovieweachrecommendationindividually.
1.

OpentheSQLWorksheetforthescottuserbyclickingSQLWorksheet

2. EnterthefollowingSQLstatementintheworksheet.
selectsum(e.sal),avg(e.sal),count(1),e.deptnofromdeptd,empegroupbye.deptno
orderbye.deptno

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

11/25

2/23/2015

SQLTuningAdvisor

NotethattheaboveSQLstatementhasanunusedreferencetothe"dept"table.

3.
SelecttheSQLstatementandclickSQLTuningAdvisor

4. TheSQLTuningAdvisoroutputappears.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

12/25

2/23/2015

SQLTuningAdvisor

5. Intheleftnavigator,clickStatistics.Inthisanalysis,objectswithstaleormissingstatisticsareidentifiedand
appropriaterecommendationsaremadetoremedytheproblem.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

13/25

2/23/2015

SQLTuningAdvisor

6. Intheleftnavigator,clickSQLProfile.Here,theSQLTuningAdvisorrecommendstoimprovetheexecutionplanby
thegenerationofaSQLProfile.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

14/25

2/23/2015

SQLTuningAdvisor

7. ClicktheDetailtabbedpagetoviewtheSQLProfileFinding.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

15/25

2/23/2015

SQLTuningAdvisor

8. Intheleftnavigator,clickIndexes.ThisrecommendswhethertheSQLstatementmightbenefitfromanindex.If
necessary,newindexesthatcansignificantlyenhancequeryperformancesareidentifiedandrecommended.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

16/25

2/23/2015

SQLTuningAdvisor

9. ClicktheOverviewtabbedpage.Inthiscase,therearenoindexrecommendations.

10. Intheleftnavigator,clickRestructureSQL.Inthisanalysis,relevantsuggestionsaremadetorestructureselected
SQLstatementsforimprovedperformance.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

17/25

2/23/2015

SQLTuningAdvisor

ImplementingSQLTuningAdvisorrecommendations
YoucanimplementtheSQLTuningAdvisorrecommendationfeature.Thiswillenableyoutoupdatethestatisticsinscott
schema.PerformthefollowingstepstoimplementtheSQLTuningAdvisorrecommendations:
1. IntheConnectionsnavigator,rightclickscottandselectGatherSchemaStatistics....

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

18/25

2/23/2015

SQLTuningAdvisor

2. InGatherSchemaStatistics,selectEstimatePercentas100fromthedropdownlistsothatallrowsineach
tableareread.Thisensuresthatthestatisticsareasaccurateaspossible.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

19/25

2/23/2015

SQLTuningAdvisor

3. ClickApply.

4. Aconfirmationmessageappears.ClickOK.

5. ToruntheSQLTuningAdvisorontheSQLstatementagain,selecttheSQLstatementandclickSQLTuning
Advisor

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

20/25

2/23/2015

SQLTuningAdvisor

6. TheSQLTuningAdvisoroutputappears.Bygatheringstatistics,theStatisticsandSQLProfileadviceisnow
removed.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

21/25

2/23/2015

SQLTuningAdvisor

7. Intheleftnavigator,clickeachoftheSQLTuningAdvisorImplementTypetocheckifalltherecommendations
havebeenimplemented.

Notetheissuesreportedtoyou:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

22/25

2/23/2015

SQLTuningAdvisor

Notetheissuesreportedtoyou:

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

23/25

2/23/2015

SQLTuningAdvisor

NotethattheRestructureSQLrecommendationtoremoveanunusedtableremains.

8.
Removethe"dept"tableintheSQLstatementandclickSQLAdvisor

9. Theoutputappears.Alloftheadvicerecommendationshavebeenremoved.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

24/25

2/23/2015

SQLTuningAdvisor

Summary
Inthistutorial,youhavelearnedhowto:
CreateaDatabaseConnection.
ProvidePrivilegestotheScottUser.
RuntheSQLTuningAdvisoronaSQLstatement.
ImplementSQLTuningAdvisorrecommendations.

AboutOracle |OracleandSun |

| Careers| ContactUs| SiteMaps|

LegalNotices| TermsofUse | YourPrivacyRights

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6

25/25

Potrebbero piacerti anche