Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Oracle Database Architecture Processing Chapter 1 The Oracle Architecture Oracle Architecture Vocabulary/Terminology • Let’s review some terms and concepts from DB in general... • http://www.hp.isc.usouthal.edu/isc563/ISC563.htm Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Review from 561 Oracle Architecture • Transaction Processing Schema Customer Sales Rep Document of Transaction Product Line Item Service Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Southern Floors Oracle Architecture • Fill in the blanks... Customer Renter Sales Clerk Rep Document Rental of Agreement Transaction Product Sander Equipment Line Item List Service Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Review from 561 Oracle Architecture • Transaction Processing Schema Clerk ------------ClerkID (PK) Other stuff Customer ------------CustomerID (PK) Other stuff Recall, the ERD won’t necessarily map to the table structure as it does in this case. Rental Agreement ------------Rental_Num (PK) CustomerID (FK) ClerkID (FK) DateTime Copyright © 2001 Harold Pardue, University of South Alabama Equipment ------------EquipID (PK) Other stuff Equipment List ------------Rental_Num (PK)(FK) EquipID (PK)(FK) Other stuff Chapter 1 The Oracle Architecture Time to look under the hood... Oracle Architecture hmm... PGA, SGA, PMON, SMON, LGWR, CKPT, DBWR, ARCH, DataFiles, Data Buffers image source: http://askanexpert.net/howto.html Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Storage Hierarchy Database Tablespace (Logical) Oracle Architecture Let’s start at the begining... Data file (Physical) Segment Extent OracleBlock OS Block Page 12 Oracle Corporation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Database Oracle Architecture (logical) Why multiple files? (physical) Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Storage Hierarchy Database Tablespace (Logical) Oracle Architecture A database is physically stored as data files. Data file (Physical) Segment Extent OracleBlock OS Block Page 12 Oracle Corporation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Datafiles Oracle Architecture Name of database At a minimum there is a SYSTEM Tablespace Physical data files DBA_DATA_FILES is a data dictionary view Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Datafiles Oracle Architecture In this case, the tablespaces match a physical file 1:1, but a Tablespace can be distributed across multiple data files. Tablespace = logical Datafile = physical Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Datafiles Oracle Architecture USER_DATA I can add a datafile to the USER_DATA tablespace. USER1ORCL.ORA USER1ORCL2.ORA SQL> ALTER TABLESPACE USER_DATA ADD DATAFILE ‘C:\ORACLE\ORA563\DATABASE\USER1ORCL2' SIZE 1M; Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Datafiles Oracle Architecture Once you add a datafile, you can’t remove it from the tablespace. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Storage Hierarchy Database Tablespace (Logical) Oracle Architecture Data files are logically grouped by tablespaces. Data file (Physical) Segment Extent OracleBlock OS Block Page 12 Oracle Corporation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tablespaces Oracle Architecture View tablespaces by querying the data dictionary. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tablespaces Oracle Architecture • You can query across tablespaces • Why organize database datafiles into these logical storage units? – Control disk space allocation – Assign space quotas for users – Control availability of data: individual tablespaces can be brought offline and online separately – Partial backup and recovery – Tuning by allocating data across multiple storage devices – Manage I/O contention Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tablespaces Oracle Architecture • Tablespaces can contain: – – – – – – Tables Views Sequences Synonyms Indexes Clusters Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tablespaces Oracle Architecture • Oracle vs. SQL Server Page 12http://www.microsoft.com/sql/techinfo/deployment/2000/MigrateOracle.asp (109 pages) Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Schemas Oracle Architecture • All objects in a Tablespace must have an owner. • Objects owned by the same user are members of that user’s schema – For example: SCOTT.DEPT indicates that the table DEPT is a member of the SCOTT schema • Therefore, ownership (by schema) is another means of logically organizing the objects in a tablespace. Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Schemas Oracle Architecture The tables in the SCOTT schema Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tables Oracle Architecture Query the data dictionary for tables in the USER_DATA tablespace Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Tables Oracle Architecture • No discussion on tables per se... • An administrative issue is when tables get very large (teraflation) – Very large database (VLDB) • What is large? – giga, tera, peta? – Numerical threshold or maintenance overhead? Recovery time? Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Partitions Oracle Architecture • Oracle supports the partitioning of tables – Dividing a table into smaller sub-tables (partitions) based on a range value. • What types of tables should be considered for partitioning? – Historical data – Tables that are static except for regularly appended data. – Tables with a logical partition column Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Partitions Oracle Architecture • Why not define separate tables? – Eg. the Sales table becomes: • • • • SalesQ1y01 SalesQ2y01 SalesQ3y01 SalesQ4O1 and so on... Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Partitions Oracle Architecture A sample partitioning In this case, each partition is a separate tablespace. image source: Oracle documentation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Views Oracle Architecture • We briefly reviewed this. • Any questions? Query DBA_VIEWS Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Sequences Oracle Architecture • Oracle doesn’t have an autonumber or identity option for the integer datatype • Instead, you define a sequence object to generate unique sequential numbers (e.g., for PKs) Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Sequences Oracle Architecture • From an application design standpoint, what is a problem with autonumber and identity? – How do you enforce uniqueness across tables? – A recent example, Senior project: wanted to name jpg files same as PK of tables (Staff, Athletes, and Journalists). Problem, not unique across tables. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Sequences Oracle Architecture • Why not generate sequences at the application level? – processing bottleneck – Inefficient in large TPS, multi-user environment • A sequence object can be used to generate unique values for a table, across tables, or for an application. • What problem does concurrency cause? • What is the solution? Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Sequences Copyright © 2001 Harold Pardue, University of South Alabama Oracle Architecture Chapter 1 The Oracle Architecture Synonym Oracle Architecture • Essentially an alias to avoid having to spell out entire qualifier • Scope is either public or schema CREATE SYNONYM market FOR scott.market_research; Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture • What’s the larger issue? – Data access method – Reduces size of scan and therefore I/O – Does not impact formulation of SQL expressions • An index is an ordered list of all the values that reside in a group of one or more columns at a given time. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture • The index contains two entries: – The key value (e.g., empno = 7369) – The ROWID • The ROWID is a unique address that specifies the row’s position in the datafile. – Object, Block, Row, Datafile Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture ROWID is a pseudocolumn Why not use ROWID as PK? Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Storage Hierarchy Oracle Architecture Database Tablespace (Logical) Segment Extent OracleBlock Data file ROWID bridges this gap (Physical) An object in a tablespace to a row in a datafile OS Block Page 12 Oracle Corporation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture • Oracle automatically creates an index on the PK of each table Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture • The most common index structure used by Oracle is a B-tree – A B-tree is an optimally height-balanced, multi-way search tree • What does it mean that Oracle maintains a shallow tree? – The maximum number of levels is 4 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture Root node What order? Branch node Leaf node Oracle corporation Doubly linked Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Indexes Oracle Architecture • Why use a B-tree? – Relatively uniform access time to ROWID. Why? – Automatically stays balanced – Efficient for both equivalence and range searches. • Where emp = 7360 • Where emp > 700 and emp < 1000 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Clusters Oracle Architecture • Another access method is clustering • I/O is reduced by storing data in clusters that are physically close to each other. – For example, Invoice and Invoice Details – Physical proximity enhances performance of SQL join statements Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Oracle Architecture Clusters image source: Oracle documentation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Storage Hierarchy Database Tablespace (Logical) Oracle Architecture The space within a tablespace is allocated as segments. Data file (Physical) Segment Extent OracleBlock OS Block Page 12 Oracle Corporation Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Segments Oracle Architecture • Tablespaces are large logical areas for the creation of objects (e.g., tables, views, indexes, etc... • The space for an object is allocated in terms of segments. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Segments Copyright © 2001 Harold Pardue, University of South Alabama Oracle Architecture Chapter 1 The Oracle Architecture Extents Oracle Architecture • A segment is comprised of multiple extents Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Extents Oracle Architecture • An extent is a set of contiguous data blocks used to store a particular type of information. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Extents Oracle Architecture • An initial extent is allocated. • When an extent becomes full, another extent from the freespace in the tablespace is allocated to the segment. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Data Blocks Oracle Architecture • Data blocks are the smallest unit of I/O for Oracle • When creating a database, you should define data blocks to be a multiple of the OS data blocks. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Database Oracle Architecture • So... that’s the basics of the Oracle architecture from a data storage perspective. • But in of itself, there’s not much you can do with the data. • Major distinction – Database versus Instance Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Instance Oracle Architecture Why multiple instances? Page 12 Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture OPS Oracle Architecture Oracle Parallel Server (OPS) enables one database to be mounted and opened concurrently by multiple instances. High availability Better scalability Load balancing Each OPS instance is like any standalone Oracle instance and runs on a separate node having its own CPU and memory. The database resides on a disk subsystem shared by all nodes. source: Page 12http://www.oreilly.com/catalog/oraclepp/chapter/ch01.html Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Interfaces Two interface points Copyright © 2001 Harold Pardue, University of South Alabama Oracle Architecture Most tuning activity will focus on these two points. Chapter 1 The Oracle Architecture The big picture... Oracle Architecture Now let’s look at the SGA We’ve looked at this so far... image source: http://www.windowsitlibrary.com/Content/277/02/1.html Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture SGA Oracle Architecture • When an instance is started, Oracle allocates space in memory for shared processes • An area in computer memory used to hold information for a particular instance Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture SGA Oracle Architecture System Global Area Database buffer cache Redo log buffer Shared Pool Library Cache Dictionary Cache Copyright © 2001 Harold Pardue, University of South Alabama Cursors Chapter 1 The Oracle Architecture SGA Oracle Architecture • What is the purpose of the SGA? • Why create all these buffers and caches? – Avoid disk I/O – Users can access, share, and modify data in memory without the necessity of continuously reading and writing to disk storage Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture SGA Oracle Architecture • Database buffer cache – Collection of buffers the size of the database blocks – Free space managed with LRU algorithm – CRUD performed in memory, deferred I/O Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture SGA Oracle Architecture • Shared Pool – Library cache stores parsed SQL and execution plan (reuse) • text of SQL expression • parse tree: compiled version • execution plan – Dictionary cache stores recently access dictionary values • Shared by multiple users – improves performance in multi-user environments Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture SGA Oracle Architecture • Redo log buffer – Huh? why a redo? – Stuff happens... • The redo buffer stores the information needed to reconstruct a transaction in the event of a failure – This information will eventually be written to the redo log file(s) Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture PGA Oracle Architecture • Program Global Area • Private storage area for a user’s process – Although, e.g., a parsed SQL statement might be common to multiple users, the parameters and qualifiers might not. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Processes Oracle Architecture Work gets accomplished through the user, server, and background processes image source: http://www.windowsitlibrary.com/Content/277/02/1.html Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture User Processes Oracle Architecture • Any program or system designed to access the Oracle database – Application program written to access Oracle database – An Oracle Tool such as SQL*Plus • Creates connection • A specific connection is a session, e.g., session for SCOTT/TIGER Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Server Processes Oracle Architecture • Server processes manage connections and perform the I/O against the datafiles – Parse and execute SQL statements – Retrieve data blocks from datafiles into SGA if needed – Returns results of SQL statements Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Background processes handle all the oddsand-ends (specific tasks) of interacting with the database – – – – – – – – – DBWR LGWR CKPT SMON PMON ARCH RECO Dnnn LCKn Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Database Write (DBWR) • Writes modified data from buffers in cache to datafiles on disk • When immediately? Deferred? • When should DBWR write to disk? – At the conclusion of transaction? • Checkpoint • Dirty list if full • Timeout Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Log Write (LGWR) • Writes redo information from the redo buffer to the redo log file • Because DBWR defers I/O operations to the datafiles, the LGWR needs to write to the redo log file when transaction is committed – option: group committ or mulitple LGWR slaves Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Check Point (CKPT) • The point at which the DBWR writes all modified database buffers (buffers on the dirty list) to the data files • The dirty list is a list of all dirty buffers, i.e., buffers that contain modified data Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • A “Check Point” as an event is when the data is written. The LGWR causes a check point • The CKPT process forces a check point to occur Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • System Monitor (SMON) – Checks to see whether recovery is needed – Removes temporary or unneeded objects from the database – House-cleaning function. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Process Monitor (PMON) • Watches over the user processes – Releases locked resources – cleans up behind failed user processes Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Archiver (ARCH) • Redo log files will eventually be overwritten • The archiver archives logs such that a complete history of all transactions for the database are maintained. Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture Background Processes Oracle Architecture • Recoverer (RECO) – Attempts to resolve transaction failures in distributed databases (i.e., SQL statements issued against tables located on different machines) Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture External Structures Oracle Architecture • Redo logs • Control files • Trace files and alert files Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture