Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 1.544 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
1.544
Dung lượng
8,29 MB
Nội dung
WWW.EBOOKWORLD.CO.NR Expertone-on-oneOracle 2 This page intentionally left blank Expertone-on-oneOracle 3 Content Introduction 18 WhatthisBookisAbout 18 WhoShouldUsethisBook? 19 HowThisBookisStructured 20 UnderstandingtheDatabase 21 DatabaseStructuresandUtilities 22 Performance 23 AdvancedSQLFeatures 23 Extensibility 24 Security 25 Appendices 26 Conventions 26 SourceCodeandUpdates 27 SettingUp 28 Overview 28 TheSQL*PLUSEnvironment 28 SettingupAUTOTRACEinSQL*PLUS 30 CCompilers 32 CodingConventions 32 OtherIssues 33 Chapter1:DevelopingSuccessfulOracleApplications 35 Overview 35 MyApproach 36 TheBlackBoxApproach 37 How(andhownot)toDevelopDatabaseApplications 41 UnderstandingOracleArchitecture 41 UnderstandingConcurrencyControl 48 DatabaseIndependence? 57 HowDoIMakeitRunFaster? 71 TheDBA‐DeveloperRelationship 73 Summary 74 Chapter2:Architecture 76 Overview 76 TheServer 76 TheFiles 84 ParameterFiles 84 DataFiles 87 TempFiles 91 ControlFiles 91 RedoLogFiles 92 Expertone-on-oneOracle 4 FilesWrap‐Up 96 TheMemoryStructures 97 PGAandUGA 97 SGA 103 MemoryStructuresWrap‐Up 115 TheProcesses 115 ServerProcesses 116 BackgroundProcesses 122 SlaveProcesses 130 Summary 132 Chapter3:LockingandConcurrency 133 Overview 133 WhatareLocks? 133 LockingIssues 136 LostUpdates 136 Blocking 140 Deadlocks 141 LockEscalation 146 TypesofLock 147 DMLLocks 147 DDLLocks 155 LatchesandInternalLocks(Enqueues) 159 ManualLockingandUser‐DefinedLocks 160 WhatisConcurrencyControl? 161 TransactionIsolationLevels 162 READUNCOMMITTED 163 READCOMMITTED 165 REPEATABLEREAD 167 SERIALIZABLE 170 Read‐OnlyTransactions 172 Summary 173 Chapter4:Transactions 175 Overview 175 TransactionControlStatements 175 IntegrityConstraintsandTransactions 182 BadTransactionHabits 184 DistributedTransactions 191 RedoandRollback 194 Summary 198 Chapter5:RedoandRollback 200 Overview 200 Redo 200 WhatDoesaCOMMITDo? 201 Expertone-on-oneOracle 5 WhatDoesaROLLBACKDo? 208 HowMuchRedoAmIGenerating? 209 CanITurnOffRedoLogGeneration? 221 CannotAllocateaNewLog? 224 BlockCleanout 226 LogContention 230 TemporaryTablesandRedo/Rollback 232 AnalyzingRedo 235 Rollback 236 WhatGeneratestheMost/LeastUndo? 236 SETTRANSACTION 236 ʹORA‐01555:snapshottoooldʹ 237 Summary 250 Chapter6:DatabaseTables 252 Overview 252 TypesofTables 252 Terminology 254 HighWaterMark 254 FREELISTS 255 PCTFREEandPCTUSED 258 INITIAL,NEXT,andPCTINCREASE 265 MINEXTENTSandMAXEXTENTS 265 LOGGINGandNOLOGGING 266 INITRANSandMAXTRANS 266 HeapOrganizedTable 266 IndexOrganizedTables 271 IndexOrganizedTablesWrap‐up 286 IndexClusteredTables 286 IndexClusteredTablesWrap‐up 295 HashClusterTables 295 HashClustersWrap‐up 306 NestedTables 306 NestedTablesSyntax 307 NestedTableStorage 317 NestedTablesWrap‐up 320 TemporaryTables 321 TemporaryTableWrap‐up 329 ObjectTables 330 ObjectTableWrap‐up 339 Summary 339 Chapter7:Indexes 341 Overview 341 AnOverviewofOracleIndexes 342 Expertone-on-oneOracle 6 B*TreeIndexes 343 ReverseKeyIndexes 348 DescendingIndexes 350 WhenshouldyouuseaB*TreeIndex? 351 B*TreesWrap‐up 360 BitmapIndexes 361 WhenShouldyouuseaBitmapIndex? 362 BitmapIndexesWrap‐up 364 Function‐BasedIndexes 364 ImportantImplementationDetails 365 Function‐BasedIndexExample 365 Caveat 375 Function‐BasedIndexWrap‐up 376 ApplicationDomainIndexes 376 ApplicationDomainIndexesWrap‐up 378 FrequentlyAskedQuestionsAboutIndexes 378 DoIndexesWorkOnViews? 378 IndexesandNulls 378 IndexesonForeignKeys 382 WhyisnʹtmyIndexGettingUsed? 383 AremyIndexesBeingUsed? 389 Myth:SpaceisNeverReusedinanIndex 390 Myth:MostDiscriminatingElementsShouldbeFirst 394 Summary 398 Chapter8:ImportandExport 400 Overview 400 AQuickExample 400 WhyYouMightUseIMPandEXP 402 DetectingCorruption 402 ExtractingDDL 403 CloningSchemas 403 TransportingTablespaces 403 RebuildingInstances 403 CopyingDatabetweenPlatforms 404 HowTheyWork 404 TheOptions 404 LargeExports 409 SubsettingData 414 TransportingData 415 GettingtheDDL 421 BackupandRecovery 429 IMP/EXPisnotaReorganizationTool(AnyMore) 429 ImportingintoDifferentStructures 430 Expertone-on-oneOracle 7 DirectPathExports 435 CaveatsandErrors 436 Cloning 436 UsingIMP/EXPAcrossVersions 445 WheredidmyIndexesgo? 446 NamedversusDefault‐NamedConstraints 449 NationalLanguageSupport(NLS)Issues 453 TablesSpanningMultipleTablespaces 455 Summary 461 Chapter9:DataLoading 462 Overview 462 AnIntroductiontoSQL*LOADER 462 Howto 469 LoadDelimitedData 469 LoadFixedFormatData 473 LoadDates 476 LoadDataUsingSequencesandOtherFunctions 477 UpdateExistingRowsandInsertNewRows 483 LoadReport‐StyleInputData 486 LoadaFileintoaLONGRAWorLONGField 489 LoadDatawithEmbeddedNewlines 490 UnloadData 502 LoadLOBs 514 LoadVARRAYS/NestedTableswithSQLLDR 526 CallSQLLDRfromaStoredProcedure 529 Caveats 535 YouCannotPickaRollbackSegmenttoUse 535 TRUNCATEAppearstoWorkDifferently 535 SQLLDRDefaultstoCHAR(255) 535 CommandLineOverridesControlFile 536 Summary 536 Chapter10:TuningStrategiesandTools 537 Overview 537 IdentifyingtheProblem 537 MyApproach 539 TuningisaConstantthing 540 BindVariablesandParsing(Again) 545 AmIUsingBindVariables? 562 BindVariablesandParsingWrap‐Up 565 SQL_TRACE,TIMED_STATISTICS,andTKPROF 565 SettingUpTracing 566 UsingandInterpretingTKPROFOutput 569 UsingandInterpretingRawTraceFiles 580 Expertone-on-oneOracle 8 SQL_TRACE,TIMED_STATISTICS,andTKPROFWrap‐Up 593 DBMS_PROFILER 594 Instrumentation 594 StatsPack 597 SettingupStatsPack 597 StatsPackWrap‐Up 618 V$Tables 619 V$EVENT_NAME 619 V$FILESTATandV$TEMPSTAT 620 V$LOCK 620 V$MYSTAT 620 V$OPEN_CURSOR 622 V$PARAMETER 623 V$SESSION 623 V$SESSION_EVENT 626 V$SESSION_LONGOPS 627 V$SESSION_WAIT 627 V$SESSTAT 627 V$SESS_IO 627 V$SQL,V$SQLAREA 627 V$STATNAME 628 V$SYSSTAT 628 V$SYSTEM_EVENT 628 Summary 628 Chapter11:OptimizerPlanStability 630 Overview 630 AnOverviewoftheFeature 630 UsesofOptimizerPlanStability 634 AMethodtoImplementTuning 634 ADevelopmentTool 640 ToSeetheIndexesUsed 642 ToSeewhatSQLisExecutedbyanApplication 642 HowOptimizerPlanStabilityWorks 643 OUTLINESandOUTLINE_HINTS 643 CreatingStoredOutlines 646 PrivilegesNeededforStoredOutlines 646 UsingDDL 647 UsingALTERSESSION 648 TheOUTLNUser 649 MovingOutlinesfromDatabasetoDatabase 650 GettingJusttheRightOutline 651 ManagingOutlines 654 ViaDDL 654 Expertone-on-oneOracle 9 TheOUTLN_PKGPackage 657 Caveats 661 OutlineNamesandCase 661 ALTERSESSIONIssue 663 DROPUSERdoesnotDropOutlines 663 ʹCURSOR_SHARING=FORCEʹandOutlines 664 OutlinesUseSimpleTextMatching 665 OutlinesbyDefaultareintheSYSTEMTablespace 666 OR‐Expansion 666 Performance 667 TheNamespaceofOutlinesisGlobal 672 ErrorsyouMightEncounter 673 ORA‐18001ʺnooptionsspecifiedforALTEROUTLINEʺ 673 ORA‐18002ʺthespecifiedoutlinedoesnotexistʺ 674 ORA‐18003ʺanoutlinealreadyexistswiththissignatureʺ 674 ORA‐18004ʺoutlinealreadyexistsʺ 674 ORA‐18005‐18007 674 Summary 675 Chapter12:AnalyticFunctions 676 Overview 676 AnExample 676 HowAnalyticFunctionsWork 681 TheSyntax 681 TheFunctions 698 Examples 702 TheTOP‐NQuery 702 PivotQuery 714 AccessingRowsAroundYourCurrentRow 723 Caveats 728 PL/SQLandAnalyticfunctions 728 AnalyticFunctionsintheWhereClause 730 NULLSandSorting 731 Performance 733 Summary 734 Chapter13:MaterializedViews 735 Overview 735 ABriefHistory 735 WhatyouʹllneedtoruntheExamples 737 AnExample 737 UsesofMaterializedViews 745 HowMaterializedViewsWork 745 SettingUp 746 InternalMechanics 747 Expertone-on-oneOracle 10 MakingsureyourViewgetsused 750 Constraints 750 Dimensions 756 DBMS_OLAP 767 EstimatingSize 767 DimensionValidation 769 RecommendingMaterializedViews 772 Caveats 774 MaterializedViewsareNotDesignedforOLTPSystems 774 QueryRewriteIntegrity 774 Summary 775 Chapter14:Partitioning 777 Overview 777 TheUsesofPartitioning 777 IncreasedAvailability 777 ReducedAdministrativeBurden 780 EnhancedDMLandQueryPerformance 781 HowPartitioningWorks 783 TablePartitioningSchemes 784 PartitioningIndexes 789 Summary 813 Chapter15:AutonomousTransactions 814 Overview 814 AnExample 814 WhyUseAutonomousTransactions? 817 AuditingthatCanNotbeRolledBack 817 AMethodtoAvoidaMutatingTable 821 PerformingDDLinTriggers 822 WritingtotheDatabase 828 ToDevelopMoreModularCode 839 HowTheyWork 839 TransactionalControl 840 Scope 842 EndinganAutonomousTransaction 849 Savepoints 850 Caveats 853 NoDistributedTransactions 853 PL/SQLOnly 853 TheEntireTransactionRollsBack 853 Transaction‐LevelTemporaryTables 855 MutatingTables 857 ErrorsYouMightEncounter 860 ORA‐06519ʺactiveautonomoustransactiondetectedandrolledbackʺ 860 [...]... 33 Expertone-on-oneOracle you will find that in order to drop it, you need to: tkyte@TKYTE816> drop java source ʺdemoʺ; Java dropped. Remember to use the double quotes around the identifier for Java objects as they are created and stored in mixed case. 34 Expertone-on-oneOracle Chapter 1: Developing Successful Oracle Applications Overview I spend the bulk of my time working with Oracle database software and, more to the point, ... Chapter 3, Locking and Concurrency. Different databases have different ways of doing things (what works well in SQL Server may not work as well in Oracle) and 21 Expertone-on-oneOracle understanding how Oracle implements locking and concurrency control is absolutely vital to the success of your application. This chapter discussed Oracle s basic approach to these issues, the types of locks that can be applied (DML, DDL, latches ) and the problems that can arise if locking ... Add an Erratum 1541 How to Tell Us Exactly What You Think 1543 17 Expertone-on-oneOracle Introduction The inspiration for the material contained in this book comes from my experiences developing Oracle software and working with fellow Oracle developers, helping them build reliable and robust applications based on the Oracle database. The book is basically a reflection of what I do everyday and of the issues I see people encountering each and ... not referring to bugs, but really the way it is supposed to work and what the feature was really designed to do). 18 Expertone-on-oneOracle Who Should Use this Book? The target audience for this book is anyone who develops applications with Oracle as the database backend. It is a book for professional Oracle developers who need to know how to get things done in the database. The practical nature of the book means that many ... the other 10,000 to 20,000 pages of documentation are for) but it will educate you on all of the important concepts. This manual touches the following topics (to name a few): 19 Expertone-on-oneOracle • • • • • • • • • • • The structures in the database, how data is organized and stored. Distributed processing. Oracle s memory architecture. Oracle s process architecture. Schema objects you will be using (tables, indexes, clusters, and so on). Built‐in data types and user‐defined data types. ... things to be very cut and dry; in other words, easy. Oracle presents the developer with almost unlimited choice. No one ever says ʹyou canʹt do that in Oracle ‐ they say ʹhow many different ways would you like to do that in Oracle? ʹ I hope that this book will help you make the correct choice. It is a book for those people who appreciate the choice but would also like some guidelines and practical implementation details on Oracle features and functions. For example, ... Caveats of using this feature 20 Expertone-on-oneOracle Handling errors (proactively) • A summary to bring it all together. There will be lots of examples, and lots of code, all of which will be available for download at http://www.apress.com/ Following is a detailed breakdown of the content of each section: Understanding the Database • Chapter 1, Developing Successful Oracle Applications. This chapter sets out my ... Appendix AH: DBMS_LOGMNR 1339 Overview 1339 15 Expertone-on-oneOracle Overview 1341 Step 1: Creating the Data Dictionary 1341 Step 2: Using Log Miner 1345 Options and Usage 1352 Using Log Miner to Find Out When .1355 PGA Usage 1357 Log Miner Limits 1359 Oracle Object Types 1359 Chained or Migrated Rows ... Chapter 12, Analytic Functions. Certain questions are asked of the database very regularly, but the queries that can answer them are difficult to write in straight SQL 23 Expertone-on-oneOracle • • • • (and will not always perform quickly, anyway). Oracle 8.1.6 introduced analytic functions. These functions add extensions to the SQL language that make such queries easier to code, and dramatically increase performance over the equivalent ... Web, which gives rise to situations where your client presents their credentials to a middle‐tier application server, before actually accessing your database. We will see 25 Expertone-on-oneOracle • how this feature can be implemented and how it works. We will look at how you can grant privileges and audit proxy accounts. Chapter 23, Invoker and Definer Rights. Starting with Oracle 8i, we can now grant a different set of privileges to different users of a stored procedure. With . WWW.EBOOKWORLD.CO.NR Expert one-on-one Oracle 2 This page intentionally left blank Expert one-on-one Oracle 3 Content Introduction 18 WhatthisBookisAbout. 1543 Expert one-on-one Oracle 18 Introduction Theinspirationforthematerialcontainedinthisbookcomesfrommyexperiences developing Oracle softwareandworkingwithfellow Oracle developers,helpingthem buildreliableandrobustapplicationsbasedonthe Oracle database.Thebookisbasicallya reflectionofwhatIdoeverydayandoftheissuesIseepeopleencounteringeachand everyday. IcoveredwhatIfeltwasmostrelevant‐namelythe Oracle databaseanditsarchitecture.I couldhavewrittenasimilarly‐titledbookexplaininghowtodevelopanapplicationusing aspecificlanguageandarchitecture‐forexample,oneusingJavaServerPagesthatspeak toEnterpriseJavaBeans,thatuseJDBCtocommunicatewith Oracle. However,attheend oftheday,youreallydoneedtounderstandthetopicscoveredhereinordertobuildsuch anapplicationsuccessfully.ThisbookdealswithwhatIbelieveneedstobeuniversally knowntodevelopsuccessfullywith Oracle, whetheryouareaVisualBasicprogrammer usingODBC,aJavaprogrammerusingEJBsandJDBC,oraPerlprogrammerusingDBI Perl.Thisbookdoesnotpromoteanyspecificapplicationarchitecture;itdoesnotcompare 3‐tiertoclient‐server.Rather,itcoverswhatthedatabasecandoandwhatyoumust understandaboutthewayitworks.Sincethedatabaseisattheheartofanyapplication architecture,thebookshouldhaveabroadaudience. WhatthisBookisAbout Oneoftheproblemswithhavingplentyofdevelopmentoptionsisintryingtofigureout whichonemightbethebestchoiceforyourparticularneeds.Everyonewantsasmuch flexibilityaspossible(asmanychoicesastheycanpossiblyhave)buttheyalsowant thingstobeverycutanddry;inotherwords,easy. Oracle presentsthedeveloperwith almostunlimitedchoice.NooneeversaysʹyoucanʹtdothatinOra. Familiaritywiththe Oracle ServerConceptsManual. Afewwordsonthatlastpoint:duetoitsvastsize,manypeoplefindthe Oracle documentationsettobesomewhatintimidating.Ifyouarejuststartingoutorhavenʹtread anyofitasyet,Icantellyouthatthe Oracle8 iConceptsmanualisexactlytherightplaceto start.Itisabout800pageslongandtouchesonmanyofthemajor Oracle conceptsthat youneedtoknowabout.Itmaynotgiveyoueach,andeverytechnicaldetail(thisiswhat theother10,000to20,000pagesofdocumentationarefor)butitwilleducateyouonallof theimportantconcepts.Thismanualtouchesthefollowingtopics(tonameafew): Expert one-on-one Oracle 20 • Thestructuresinthedatabase,howdataisorganizedandstored. • Distributedprocessing. • Oracle smemoryarchitecture. • Oracle sprocessarchitecture. •