Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB25/003 Version No.2.0 Objectives To Recall RDBMS concepts To introduce ORACLE and its products To introduce Oracle Client/S
Trang 1Oracle - OS (LC)
Trang 2Oracle Architecture
Oracle Day 1
Trang 3Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Objectives
To Recall RDBMS concepts
To introduce ORACLE and its products
To introduce Oracle Client/Server Architecture
To explain Oracle Physical structure-Data Files, Control Files,
Redo Files
To explain Oracle Logical Structure- Tablespaces,
Segments, Extents, Blocks
To introduce Schema objects-Tables, Sequences,
Synonyms, Views, Indexes and Clusters
To explain Oracle Memory Structures and Background
Processes, Data Dictionary
Trang 4Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Trang 5Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
What is Oracle?
Oracle is a Relational Database Management System
• It is a management system which uses the Relational Data Model
• In the Relational Data Model, data is seen by the users in form of tables
Trang 6Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Trang 7Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Database Servers
• Oracle 10g Database
• Oracle 9i Database
• Oracle 8i Database
Trang 8Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Application Development Tools
• Oracle Developer (Includes Forms, Reports, Graphics etc.)
• Oracle Designer
• Oracle Discoverer
• PL/SQL (Technology)
Trang 9Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Oracle Database Server
Oracle Database server:
– Is a database management system
that provides an open,
comprehensive, integrated approach
Trang 10Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Oracle Database Server Architecture
Control files Datafiles
Database
Redo Log files
Instance
SGA
Redo Log Buffer Shared Pool
Data Dictionary Cache
Library Cache
DBWR SMON
User process
Server process
PGA
Database Buffer Cache
Large Pool
Password file
Parameter file
Archived Log files
Trang 11Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Oracle Database
Oracle Database
Oracle Database:
– Is a collection of data that is treated as a unit
– Consists of three file types
Control files
Datafiles
Redo Log files
Trang 12Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Oracle Instance
Oracle Instance:
• Is a means to access an Oracle database
• Always open one and only one database
• Consists of memory structures and background processes
Instance
SGA
Redo Log Buffer Shared Pool
Data Dictionary
Cache
Library Cache
DBWR SMON
Database Buffer Cache
Large Pool
Background Processes Memory structures
Trang 13Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Establishing a Connection
and Creating a Session
Connecting to an Oracle Instance:
– Establishing a user connection
– Creating a session
Session created
Database user
User process
Server process
Connection established
Oracle Server
Trang 14Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Oracle Database
Physical Structure
The physical structure includes three types of files:
• Control files, Data files, Redo log files.
Other key files:
• Parameter file
• Password file
• Archived redo log file
Passwordfile
Parameterfile
Archived Log files
Control files
Datafiles
Redo Log files
Trang 15Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Memory Structure
• Oracle’s memory structure consists of two memory areas known as:
– System Global Area (SGA): Allocated at instance startup, and is a fundamental component of an Oracle Instance
– Program Global Area (PGA): Allocated when the server process is started
Trang 16Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
System Global Area
The SGA consists of several memory structures:
• Shared Pool
• Database Buffer Cache
• Redo Log Buffer
• Other structures (for example, lock and latch management, statistical data)
There are additional memory structures that can be configured within
the SGA:
• Large Pool
Trang 17Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Shared Pool
– Used to store:
• Most recently executed SQL statements
• Most recently used data definitions– It consists of two key performance-related memory structures:
Trang 18Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Library Cache
– Stores information about the most recently used SQL and PL/SQL statements
– Enables the sharing of commonly used statements
– Is managed by a least recently used (LRU) algorithm
– Consists of two structures:
• Shared SQL area
• Shared PL/SQL area– Size determined by the Shared Pool sizing
Trang 19Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Data Dictionary Cache
– A collection of the most recently used definitions in the database
– Includes information about database files, tables, indexes, columns, users, privileges, and other database objects– During the parse phase, the server process looks at the data dictionary for information to resolve object names and validate access
– Caching data dictionary information into memory improves response time on queries and DML
– Size determined by the Shared Pool sizing
Trang 20Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Database Buffer Cache
– Stores copies of data blocks that have been retrieved from the
datafiles– Enables great performance gains when you obtain and update data– Managed through the LRU algorithm
– DB_BLOCK_SIZE determines the block size
Database Buffer
Cache
Trang 21Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Redo Log Buffer
– Records all changes made to the database data blocks
– Primary purpose is recovery
– Changes recorded within are called redo entries
– Redo entries contain information to reconstruct or redo changes– Size defined by LOG_BUFFER
Redo Log Buffer
Trang 22Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Large Pool
– An optional area of memory in the SGA – Relieves the burden placed on the Shared Pool– Used for:
• Session memory (UGA) for the Shared Server
• I/O server processes
• Backup and restore operations or RMAN– Does not use an LRU list
– Sized by LARGE_POOL_SIZE
Trang 23Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Program Global Area
– Memory reserved for each user process
connecting to an Oracle database– Allocated when a process is created
– Deallocated when the process is terminated
– Used by only one process
User process
PGA Server
process
Trang 24Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Process Structure
Oracle takes advantage of various types of processes:
– User process: Started at the time a database user requests connection
to the Oracle server– Server process: Connects to the Oracle Instance and is started when a user establishes a session
– Background processes: Started when an Oracle Instance is started
Trang 25Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
User Process
– A program that requests interaction with the Oracle server
– Must first establish a connection
– Does not interact directly with the Oracle server
Database user
Server process User
process
Connection established
Trang 26Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Server Process
– A program that directly interacts with the Oracle server
– Fulfills calls generated and returns results
– Can be Dedicated or Shared Server
Connection established Session created
Database user
User process
Server process
Oracle server
Trang 27Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Trang 28Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Database Writer (DBWn)
• DBWn writes when:
– Checkpoint occurs– Dirty buffers reach threshold
– There are no free buffers– Timeout occurs
– Tablespace OFFLINE– Tablespace READ ONLY– Table DROP or
TRUNCATE
Instance SGA
Control files
Datafiles Redo Log
files Database
DBWn
Database Buffer Cache
Trang 29Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Log Writer (LGWR)
• LGWR writes:
– At commit – When one-third full– When there is 1 MB of redo
– Every three seconds– Before DBWn writes
Instance SGA
Control files
Datafiles Redo Log
files
Database
Redo Log Buffer
DBWn LGWR
Trang 30Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
System Monitor (SMON)
Control files
files
Database
InstanceSGA
SMON
Trang 31Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Process Monitor (PMON)
• Cleans up after failed processes by:
– Rolling back the transaction
– Releasing locks– Releasing other resources– Restarting dead
dispatchers
PGA area
Instance SGA
PMON
Trang 32Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Checkpoint (CKPT)
• Responsible for:
– Signaling DBWn at checkpoints
– Updating datafile headers with checkpoint
information – Updating control files with checkpoint information
Control files
Datafiles Redo Log
files
Database
Instance SGA
DBWn LGWR CKPT
Trang 33Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Archiver (ARCn)
– Optional background process
– Automatically archives online redo logs when ARCHIVELOG mode is set– Preserves the record of all changes made to the database
ARCn
Archived Redo Log files
Control files Datafiles Redo Log
files
Trang 34Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Control File
– A small binary file
– Defines current state of physical database
– Maintains integrity of database
– Required:
• At MOUNT state during database startup
• To operate the database– Linked to a single database
– Loss may require recovery
– Sized initially by
CREATE DATABASE
Control files Database
Trang 35Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Control File Contents
• A control file contains the following entries:
– Database name and identifier– Time stamp of database creation– Tablespace names
– Names and locations of datafiles and redo log files– Current redo log file sequence number
– Checkpoint information– Begin and end of undo segments– Redo log archive information
– Backup information
Trang 36Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Redo Log Files
Redo log files have the following characteristics:
– Record all changes made to data
– Provide a recovery mechanism
– Can be organized into groups
– At least two groups required
Redo Log files
Trang 37Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Structure of Redo Log Files
Member
Trang 38Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
How Redo Log Files Work
– Redo log files are used in a cyclic fashion
– When a redo log file is full, LGWR will move to the next log group
• Called a log switch
• Checkpoint operation also occurs
• Information written to the control file
Trang 39Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Archived Redo Log Files
– Filled online redo log files can be archived
– There are two advantages in running the database in ARCHIVELOG mode and archiving redo log files:
• Recovery: A database backup together with online and archived redo log files can guarantee recovery of all committed
transactions
• Backup: This can be performed while the database is open
– By default, database is created in NOARCHIVELOG mode
Trang 40Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Archived Redo Log Files
– Accomplished automatically by ARCn– Accomplished manually through SQL statements– When successfully archived:
• An entry in the control file is made
• Records: archive log name, log sequence number, and high and low system change number (SCN)
• Filled redo log file cannot be reused until:
– A checkpoint has taken place – File has been archived by ARCn
– Can be multiplexed– Maintained by the DBA
Trang 41Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Logical Structure
– Dictates how the physical space of a database is used
– Hierarchy consisting of tablespaces, segments, extents, and blocks
Tablespace
Datafile Segment
Blocks Extent
Segment
Trang 42Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Tablespaces and Datafiles
• Oracle stores data logically in tablespaces and physically in datafiles.
– Tablespaces:
• Can belong to only one database at a time
• Consist of one or more datafiles
• Are further divided into logical units of storage – Datafiles:
• Can belong to only one tablespace and one database
• Are a repository for schema object data
Database Tablespace Datafiles
Trang 43Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Types of Tablespaces
– SYSTEM tablespace
• Created with the database
• Contains the data dictionary
• Contains the SYSTEM undo segment– Non-SYSTEM tablespace
• Separate segments
• Eases space administration
• Controls amount of space allocated to a user
Trang 44Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Creating Tablespaces
CREATE TABLESPACE userdata
DATAFILE '/ora/data01.dbf' SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 200M;
• A tablespace is created using the command:
• CREATE TABLESPACE
Trang 45Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Dropping Tablespaces
– Cannot drop a tablespace if it:
• Is the SYSTEM tablespace
• Has active segments– INCLUDING CONTENTS drops the segments
– INCLUDING CONTENTS AND DATAFILES deletes datafiles
– CASCADE CONSTRAINTS drops all referential integrity constraints
DROP TABLESPACE userdata
INCLUDING CONTENTS AND DATAFILES;
Trang 46Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Obtaining Tablespace Information
• Obtaining tablespace and datafile information can be obtained by querying the following:
– Tablespaces:
• DBA_TABLESPACES– Datafile information:
• DBA_DATA_FILES
Trang 47Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Trang 48Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Trang 49Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Rollback Segments: Purpose
Transaction rollback
Transaction recovery
Rollback segment
Read consistency
Trang 50Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Read Consistency
Trang 51Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Types of Rollback Segments
– SYSTEM: Used for objects in the SYSTEM tablespace
– Non-SYSTEM: Used for objects in other tablespaces:
– Private: Acquired by a single instance– Public: Acquired by any instance
– Deferred: Used when tablespaces are taken offline immediate, temporary, or for recovery
Trang 52Copyright © 2005, Infosys Technologies Ltd
ER/CORP/CRS/DB25/003 Version No.2.0
Extent Allocation and Deallocation
– An extent is a chunk of space used by a segment within a tablespace
– An extent is allocated when the segment is:
• Created
• Extended
• Altered– An extent is deallocated when the segment is:
• Dropped
• Altered
• Truncated