73
Chapter 1 The Oracle Architecture Database Processing Oracle Architecture

Chapter 1 The Oracle Architecture Database Processing Oracle Architecture

Embed Size (px)

Citation preview

Chapter 1

The Oracle Architecture

Database Processing Oracle Architecture

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Vocabulary/Terminology

Page 12

• Let’s review some terms and concepts from DB in general...

• http://www.hp.isc.usouthal.edu/isc563/ISC563.htm

Oracle Architecture

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Review from 561• Transaction Processing Schema

Customer Sales Rep

Documentof

TransactionLine Item

Product

Service

Oracle Architecture

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Southern Floors• Fill in the blanks...

Customer Sales Rep

Documentof

TransactionLine Item

Product

Service

Renter Clerk

RentalAgreement

EquipmentList

Sander

Oracle Architecture

Service

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Review from 561• Transaction Processing Schema

Oracle Architecture

Customer-------------CustomerID (PK)Other stuff

Clerk-------------ClerkID (PK)Other stuff

Rental Agreement-------------Rental_Num (PK)CustomerID (FK)ClerkID (FK)DateTime

EquipmentList-------------Rental_Num (PK)(FK)EquipID (PK)(FK)Other stuff

Equipment-------------EquipID (PK)Other stuff

Recall, the ERD won’t necessarily map to the table structure as it does in this case.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Time to look under the hood...

image source: http://askanexpert.net/howto.html

Oracle Architecture

hmm... PGA, SGA, PMON, SMON, LGWR, CKPT,

DBWR, ARCH, DataFiles, Data Buffers

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureStorage Hierarchy

Database

Tablespace

Segment

Extent

OracleBlock OS Block

Data file

(Logical) (Physical)

Oracle Corporation

Let’s start at the begining...

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Database

Page 12

Oracle Architecture

Why multiple files?

(logical)

(physical)

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureStorage Hierarchy

Database

Tablespace

Segment

Extent

OracleBlock OS Block

Data file

(Logical) (Physical)

Oracle Corporation

A database is physically stored as data files.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle Architecture

Name of database

At a minimum there is a SYSTEM Tablespace

Physical data files

DBA_DATA_FILES is a data dictionary view

Datafiles

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 = logicalDatafile = physical

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Datafiles Oracle Architecture

I can add a datafile to the USER_DATA tablespace.

USER_DATA

USER1ORCL2.ORAUSER1ORCL.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

Page 12

Oracle ArchitectureStorage Hierarchy

Database

Tablespace

Segment

Extent

OracleBlock OS Block

Data file

(Logical) (Physical)

Oracle Corporation

Data files are logically grouped by tablespaces.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureTablespacesView tablespaces by querying the data dictionary.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

• 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

Oracle ArchitectureTablespaces

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

• Tablespaces can contain:– Tables– Views– Sequences– Synonyms– Indexes– Clusters

Oracle ArchitectureTablespaces

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

• Oracle vs. SQL Server

Oracle ArchitectureTablespaces

http://www.microsoft.com/sql/techinfo/deployment/2000/MigrateOracle.asp (109 pages)

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

• 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.

Oracle ArchitectureSchemas

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureSchemas

The tables in the SCOTT schema

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureTables

Query the data dictionary for tables in the USER_DATA tablespace

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureTables

• 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?

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitecturePartitions

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Why not define separate tables?– Eg. the Sales table becomes:

• SalesQ1y01• SalesQ2y01• SalesQ3y01• SalesQ4O1 and so on...

Oracle ArchitecturePartitions

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitecturePartitionsA sample partitioning

image source: Oracle documentation

In this case, each partition is a separate tablespace.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• We briefly reviewed this.• Any questions?

Oracle ArchitectureViews

Query DBA_VIEWS

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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)

Oracle ArchitectureSequences

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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.

Oracle ArchitectureSequences

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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?

Oracle ArchitectureSequences

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureSequences

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Essentially an alias to avoid having to spell out entire qualifier

• Scope is either public or schema

Oracle ArchitectureSynonym

CREATE SYNONYM market FOR scott.market_research;

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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.

Oracle ArchitectureIndexes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureIndexes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureIndexes

ROWID is a pseudocolumn

Why not use ROWID as PK?

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Page 12

Oracle ArchitectureStorage Hierarchy

Database

Tablespace

Segment

Extent

OracleBlock OS Block

Data file

(Logical) (Physical)

Oracle Corporation

ROWID bridges this gap An object

in a tablespace to a row in a datafile

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Oracle automatically creates an index on the PK of each table

Oracle ArchitectureIndexes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureIndexes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureIndexes

Oracle corporation Doubly linked

Root node

Branch node

Leaf node

What order?

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureIndexes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureClusters

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

Page 12

Oracle ArchitectureStorage Hierarchy

Database

Tablespace

Segment

Extent

OracleBlock OS Block

Data file

(Logical) (Physical)

Oracle Corporation

The space within a tablespace is allocated as segments.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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.

Oracle ArchitectureSegments

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureSegments

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureExtents• A segment is comprised of multiple

extents

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureExtents

• 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

Oracle ArchitectureExtents

• 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

Oracle ArchitectureData Blocks

• 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

Oracle ArchitectureDatabase

• 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

Page 12

Oracle Architecture

Why multiple instances?

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

OPS

Page 12

Oracle Architecture

Oracle Parallel Server (OPS) enables one database to be mounted and opened concurrently by multiple instances.

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: http://www.oreilly.com/catalog/oraclepp/chapter/ch01.html

High availability Better scalability Load balancing

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureInterfaces

Two interface pointsMost tuning activity will focus on these two points.

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

The big picture... Oracle Architecture

image source: http://www.windowsitlibrary.com/Content/277/02/1.html

We’ve looked at this so far...

Now let’s look at the SGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureSGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Oracle ArchitectureSGA

Databasebuffercache

LibraryCache

DictionaryCache

Redo logbuffer

Cursors

System Global Area

Shared Pool

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureSGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureSGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureSGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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)

Oracle ArchitectureSGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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.

Oracle ArchitecturePGA

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

Processes Oracle Architecture

image source: http://www.windowsitlibrary.com/Content/277/02/1.html

Work gets accomplished through the user, server, and background processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureUser Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureServer Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Background processes handle all the odds-and-ends (specific tasks) of interacting with the database– DBWR– LGWR– CKPT– SMON– PMON– ARCH– RECO– Dnnn– LCKn

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The 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

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• System Monitor (SMON)– Checks to see whether recovery is

needed– Removes temporary or unneeded

objects from the database– House-cleaning function.

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Process Monitor (PMON)• Watches over the user processes

– Releases locked resources– cleans up behind failed user

processes

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Archiver (ARCH)• Redo log files will eventually be

over-written• The archiver archives logs such

that a complete history of all transactions for the database are maintained.

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Recoverer (RECO)– Attempts to resolve transaction

failures in distributed databases (i.e., SQL statements issued against tables located on different machines)

Oracle ArchitectureBackground Processes

Copyright © 2001 Harold Pardue, University of South Alabama Chapter 1 The Oracle Architecture

• Redo logs• Control files• Trace files and alert files

Oracle ArchitectureExternal Structures