SQL Tuning Advisor
-
Upload
prashanth-reddy-burri -
Category
Documents
-
view
58 -
download
2
description
Transcript of SQL Tuning Advisor
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 1/25
SQLTuningAdvisorinOracleSQLDeveloper3.0Thistutorialcontainsthefollowingsections:
PurposeTimetoCompleteOverviewSoftwareandHardwareRequirementsPrerequisitesCreatingaDatabaseConnectionProvidingPrivilegesandRemovingtheexistingStatisticsontheScottUserRunningtheSQLTuningAdvisoronaSQLstatementImplementingSQLTuningAdvisorrecommendationsSummary
PurposeThistutorialshowsyouhowtousetheSQLTuningAdvisorfeatureinOracleSQLDeveloper3.0.
TimetoCompleteApproximately20minutes.
OverviewTheSQLTuningAdvisoranalyzeshighvolumeSQLstatementsandofferstuningrecommendations.IttakesoneormoreSQLstatementsasaninputandinvokestheAutomaticTuningOptimizertoperformSQLtuningonthestatements.ItcanrunagainstanygivenSQLstatement.TheSQLTuningAdvisorprovidesadviceintheformofpreciseSQLactionsfortuningtheSQLstatementsalongwiththeirexpectedperformancebenefits.Therecommendationoradviceprovidedrelatestothecollectionofstatisticsonobjects,creationofnewindexes,restructuringoftheSQLstatement,orcreationofaSQLprofile.YoucanchoosetoaccepttherecommendationtocompletethetuningoftheSQLstatements.
OracleDatabasecanautomaticallytuneSQLstatementsbyidentifyingproblematicSQLstatementsandimplementingtuningrecommendationsusingtheSQLTuningAdvisor.YoucanalsoruntheSQLTuningAdvisorselectivelyonasingleorasetofSQLstatementsthathavebeenidentifiedasproblematic.
Inthistutorial,youlearnhowtorunandreviewtherecommendationsoftheSQLTuningAdvisor.
Note:TuningAdvisorispartoftheTuningPack,oneoftheOraclemanagementpacksandisavailableforpurchasewithEnterpriseEdition.FormoreinformationseeTheOracleTechnologyNetworkortheonlinedocumentation.
SoftwareandHardwareRequirementsThefollowingisalistofsoftwarerequirements:
OracleDatabase11gEnterpriseEditionwithaccesstotheTuningandDiagnosticmanagementpacksandwiththesampleschemainstalled.OracleSQLDeveloper3.0.
PrerequisitesBeforestartingthistutorial,youshould:
1. InstallOracleSQLDeveloper3.0fromOTN.Followthereadmeinstructionshere.
2. InstallOracleDatabase11gwiththeSampleschema.
http://www.oracle.com/technetwork/developer-tools/sql-developer/rel3-relnotes-304121.htmlhttp://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.htmlhttp://download.oracle.com/docs/cd/B28359_01/license.111/b28287/options.htm#CIHFIHFG
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 2/25
CreatingaDatabaseConnectionThefirststeptomanagingdatabaseobjectsusingOracleSQLDeveloper3.0istocreateadatabaseconnection.
Performthefollowingstepstocreateadatabaseconnection:
Note:IfyoualreadyhavedatabaseconnectionsforSCOTTandSYSTEM,youdonotneedtoperformthefollowingsteps.YoucanmovetoProvidingPrivilegestotheScottUsertopic.
1. IfyouhaveinstalledtheSQLDevelopericononyourdesktop,clicktheicontostartyourSQLDeveloperandmovetoStep4.Ifyoudonothavetheiconlocatedonyourdesktop,performthefollowingstepstocreateashortcuttolaunchSQLDeveloper3.0fromyourdesktop.
OpenthedirectorywheretheSQLDeveloper3.0islocated,rightclicksqldeveloper.exe(onWindows)orsqldeveloper.sh(onLinux)andselectSendto>Desktop(createshortcut).
2. Onthedesktop,youwillfindaniconnamedShortcuttosqldeveloper.exe.DoubleclicktheicontoopenSQLDeveloper3.0.
Note:Torenameit,selecttheiconandthenpressF2andenteranewname.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 3/25
3. YourOracleSQLDeveloperopensup.
4. IntheConnectionsnavigator,rightclickConnectionsandselectNewConnection.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 4/25
5. TheNew/SelectDatabaseConnectiondialogopens.EntertheconnectiondetailsasfollowsandclickTest.
ConnectionName:systemUsername:systemPassword:(SelectSavePassword)Hostname:localhostSID:
6. Checkforthestatusoftheconnectionontheleftbottomside(abovetheHelpbutton).ItshouldreadSuccess.ClickSaveandthenclickConnect.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 5/25
7. IntheConnectionsnavigator,tocreateanewconnectiontothescottschema,rightclickConnectionsandselectNewConnection.
8. TheNew/SelectDatabaseConnectiondialogopens.EntertheconnectiondetailsasfollowsandclickTest.
ConnectionName:scottUsername:scottPassword:(SelectSavePassword)Hostname:localhostSID:
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 6/25
9. Checkforthestatusoftheconnectionontheleftbottomside(abovetheHelpbutton).ItshouldreadSuccess.ClickSaveandthenclickConnect.
10. TheconnectionissavedandyoucanviewthetwonewlycreatedconnectionsintheConnectionslist.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 7/25
ProvidingPrivilegesandRemovingtheexistingStatisticsontheScottUserAuserrequirescertainprivilegestoruntheSQLTuningAdvisor.Also,inordertocollectandmanagestatisticsontheSCOTTschema,theexistingstatisticshavetobecleared.BelowarethestepstograntSQLTuningAdvisorprivilegesandremovetheexistingstatisticsonthescottuser.
1.ClickSQLWorksheet andselectsystemuser.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 8/25
2. TograntprivilegestothescottusertoruntheSQLTuningAdvisor,enterthefollowinglinesofcode.ClickRun
Statement .
grantadvisortoscott
grantadministersqltuningsettoscott
3. Theoutputforthestatementsisdisplayed.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 9/25
4. TheOracledatabaseallowsyoutocollectstatisticsofmanydifferentkindsinordertoimproveperformance.ToillustratesomeofthefeaturestheSQLTuningAdvisoroffers,cleartheexistingstatisticsfromtheSCOTTschema.
Todeletetheschemastatistics,enterthefollowinglineofcode.
execDBMS_STATS.DELETE_SCHEMA_STATS('scott')
SelectthestatementandclickRunStatement
.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 10/25
WiththeDBMS_STATSpackageyoucanviewandmodifyoptimizerstatisticsgatheredfordatabaseobjects.TheDELETE_SCHEMA_STATSproceduredeletesstatisticsforanentireschema.
5. Theoutputforthestatementappears.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 11/25
RunningtheSQLTuningAdvisoronaSQLstatementInthistopic,youruntheSQLTuningAdvisoronaSQLstatement.FourtypesofanalysisareperformedbytheSQLTuningAdvisorontheSQLstatement.
AlltherecommendationsaredisplayedintheOverview.Youcanalsovieweachrecommendationindividually.
1.OpentheSQLWorksheetforthescottuserbyclickingSQLWorksheet .
2. EnterthefollowingSQLstatementintheworksheet.
selectsum(e.sal),avg(e.sal),count(1),e.deptnofromdeptd,empegroupbye.deptnoorderbye.deptno
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 12/25
NotethattheaboveSQLstatementhasanunusedreferencetothe"dept"table.
3.SelecttheSQLstatementandclickSQLTuningAdvisor .
4. TheSQLTuningAdvisoroutputappears.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 13/25
5. Intheleftnavigator,clickStatistics.Inthisanalysis,objectswithstaleormissingstatisticsareidentifiedandappropriaterecommendationsaremadetoremedytheproblem.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 14/25
6. Intheleftnavigator,clickSQLProfile.Here,theSQLTuningAdvisorrecommendstoimprovetheexecutionplanbythegenerationofaSQLProfile.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 15/25
7. ClicktheDetailtabbedpagetoviewtheSQLProfileFinding.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 16/25
8. Intheleftnavigator,clickIndexes.ThisrecommendswhethertheSQLstatementmightbenefitfromanindex.Ifnecessary,newindexesthatcansignificantlyenhancequeryperformancesareidentifiedandrecommended.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 17/25
9. ClicktheOverviewtabbedpage.Inthiscase,therearenoindexrecommendations.
10. Intheleftnavigator,clickRestructureSQL.Inthisanalysis,relevantsuggestionsaremadetorestructureselectedSQLstatementsforimprovedperformance.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 18/25
ImplementingSQLTuningAdvisorrecommendationsYoucanimplementtheSQLTuningAdvisorrecommendationfeature.Thiswillenableyoutoupdatethestatisticsinscottschema.PerformthefollowingstepstoimplementtheSQLTuningAdvisorrecommendations:
1. IntheConnectionsnavigator,rightclickscottandselectGatherSchemaStatistics....
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 19/25
2. InGatherSchemaStatistics,selectEstimatePercentas100fromthedropdownlistsothatallrowsineachtableareread.Thisensuresthatthestatisticsareasaccurateaspossible.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 20/25
3. ClickApply.
4. Aconfirmationmessageappears.ClickOK.
5. ToruntheSQLTuningAdvisorontheSQLstatementagain,selecttheSQLstatementandclickSQLTuning
Advisor .
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 21/25
6. TheSQLTuningAdvisoroutputappears.Bygatheringstatistics,theStatisticsandSQLProfileadviceisnowremoved.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 22/25
7. Intheleftnavigator,clickeachoftheSQLTuningAdvisorImplementTypetocheckifalltherecommendationshavebeenimplemented.
Notetheissuesreportedtoyou:
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 23/25
Notetheissuesreportedtoyou:
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 24/25
NotethattheRestructureSQLrecommendationtoremoveanunusedtableremains.
8.Removethe"dept"tableintheSQLstatementandclickSQLAdvisor .
9. Theoutputappears.Alloftheadvicerecommendationshavebeenremoved.
-
2/23/2015 SQLTuningAdvisor
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sqldev/r30/TuningAdvisor/TuningAdvisor.htm?print=preview&imgs=visible#s6 25/25
SummaryInthistutorial,youhavelearnedhowto:
CreateaDatabaseConnection.ProvidePrivilegestotheScottUser.RuntheSQLTuningAdvisoronaSQLstatement.ImplementSQLTuningAdvisorrecommendations.
AboutOracle|OracleandSun| |Careers|ContactUs|SiteMaps|LegalNotices|TermsofUse|YourPrivacyRights
http://www.oracle.com/corporate/index.htmlhttp://www.oracle.com/corporate/index.htmlhttp://www.oracle.com/sitemaps/sitemaps.htmlhttp://www.oracle.com/corporate/employment/index.htmlhttp://www.oracle.com/corporate/contact/index.htmlhttp://www.oracle.com/html/privacy.htmlhttp://www.oracle.com/rss/index.htmlhttp://www.oracle.com/html/terms.htmlhttp://www.oracle.com/corporate/index.htmlhttp://www.oracle.com/html/copyright.html