You are on page 1of 71

Oracle Database

Workshop 1
Presented to IBRI CAS
27-Nov-2011
By Abdullah Alkalbani
Workshop Objectives
Describe Oracle Database (10g).
Identify high-level architectural components of
an Oracle Database.
Identify Oracle Database internal data
structures.
Define the mechanisms used when
processing Insert/Update/Delete statements.
Describe DBMS programs used with Oracle
Database.
10g provides better ways to
administer your database. It
takes the mountain out of the
mole hill.
9i Mountains = More effort and resources
to accomplish similar tasks in 10g

10g Mole Hills = Less effort and resources


to accomplish similar tasks in 9i.
Popular Features
Automatic Shared Memory
Management (ASMM)
Data Pump
SQL Tuning Advisor
Flashback Database
RMAN - Backupset
Compression
Most people call it a Database
Technically an Oracle Database is broken
into two high-level components

1. INSTANCE Non-persistent, memory-based


processes and structures
2. DATABASE Persistent, disk-based data
and control files
So Why Differentiate?
Most Oracle installations consist of only a
single Instance and single Database

Instance

Database
Oracle RAC is Different
Oracle Real Application Clusters allow
multiple Instances to interact with a
single Database to provide high
availability
Instance 1 Instance 2 Instance 3

Database
Instance a Little Closer
An Oracle Instance
Is a means to access an Oracle Database
Always opens one and only one Database
Consists of memory and background process
structures
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
Database a Little Closer
An Oracle Database
Is a collection of data that is treated as a unit
Consists of three file types
Picture of a Database

Oracle Database

Data Files Control Files Redo Log Files

Parameter Archived
File Log Files

Password
File
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
Memory Structure
Oracles memory structure consists of two
memory areas known as:
1. System Global Area (SGA): Allocated at
instance start up, and is a fundamental
component of an Oracle Instance
2. Program Global Area (PGA): Allocated
when the server process is started
System Global Area
The SGA consists of several memory structures:
Shared Pool
Database Buffer Cache
Redo Log Buffer
Other structures
There are two additional memory structures that
can be configured within the SGA:
Large Pool
Java Pool
System Global Area
The size of the SGA is determined by the
parameters that set the sizes of the
various pools; these parameters are
dynamic
The SGA_MAX_SIZE parameter sets the
maximum size of the SGA (so you can
limit it) and is not a dynamic parameter

Thanks Ned!
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
Shared Pool
Used to store:
Most recently executed SQL statements
Most recently used data definitions
It consists of two key performance-related
memory structures:
Library Cache
Data Dictionary Cache
Sized by the parameter
SHARED_POOL_SIZE
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 is determined by the Shared Pool sizing
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
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
Database Buffer Cache
Stores copies of data blocks that have
been retrieved from the data files
Enables great performance gains when
you obtain and update data
Managed through an LRU algorithm
DB_BLOCK_SIZE determines primary
block size
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
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
Large Pool
An optional area of memory in the SGA
Relieves the burden place on the Shared Pool
Used for:
Session memory for the Shared Server
I/O server processes
Backup and restore operations for RMAN
Does not use an LRU list
Sized by LARGE_POOL_SIZE
Can be dynamically resized
Java Pool
Services parsing requirements for Java
commands
Required if installing and using Java
Sized by JAVA_POOL_SIZE parameter
Oracle 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
User Process
A program that requests interaction with the
Oracle server
Must first establish a connection
Does not interact directly with the Oracle server

User Server
Process Process
Connection
Established
Server Process
A program that directly interacts with the
Oracle server
Fulfills calls generated and returns results
Can be dedicated or shared server
Picture of an Instance
Instance
SGA
Shared Pool

Library Database Buffer Redo Log


Cache Cache Buffer
Memory
Data Structures
Dictionary Java Pool Large Pool
Cache

Back-
PMON SMON DBWR LGWR CKPT Others Ground
Processes
Background Processes
Maintains and enforces relationships
between physical and memory structures
Mandatory background processes:
DBWn PMON CKPT
LGWR SMON
Optional background processes:
ARCn LMDn QMNn
CJQ0 LMON RECO
Dnnn LMS Snnn
LCKn Pnnn
Database Writer (DBWn)
Instance

Shared DBWn writes when:


Shared Pool
Pool SGA
Checkpoint occurs
Library Database Buffer Redo Log
Cache Cache Buffer Dirty buffers reach
Data threshold
Dictionary Java Pool Large Pool There are no free
Cache
buffers
Timeout occurs
PMON SMON DBWR LGWR CKPT Others
Tablespace OFFLINE
Tablespace READ
ONLY
Oracle Table DROP or
Database
Control Files Redo Log Files
Data Files TRUNCATE
Tablespace BEGIN
BACKUP
Log Writer (LGWR)
Instance

Shared Pool SGA


LGWR writes:
At commit
Library Database Buffer Redo Log
Cache Cache Buffer When one-third full
Data When there is 1 MB of
Dictionary Java Pool Large Pool redo
Cache
Every three seconds
PMON SMON DBWR LGWR CKPT Others
Before DBWn writes

Oracle
Database
Control Files Redo Log Files
Data Files
System Monitor (SMON)
Instance

Shared Responsibilities:
Shared Pool
Pool SGA
Instance recovery
Library Database Buffer Redo Log
Cache Cache Buffer Rolls forward
changes in online
Data
Dictionary
redo log files
Java Pool Large Pool
Cache Opens database for
user access
PMON SMON DBWR LGWR CKPT Others Rolls back
uncommitted
transactions
Coalesces free space
Oracle Deallocates temporary
Database
Data Files Control Files Redo Log Files segments
Process Monitor (PMON)
Instance

Shared Cleans up after failed


Shared Pool
Pool SGA
processes by:
Library Database Buffer Redo Log
Cache Cache Buffer Rolling back the
Data
transaction
Dictionary Java Pool Large Pool Releasing locks
Cache
Releasing other
resources
PMON SMON DBWR LGWR CKPT Others
Restarting dead
dispactchers

Oracle
Database
Control Files Redo Log Files
Data Files
Checkpoint (CKPT)
Instance

Shared Responsible for:


Shared Pool
Pool SGA
Signaling DBWn at
Library Database Buffer Redo Log
Cache Cache Buffer checkpoints
Data Updating datafile
Dictionary Java Pool Large Pool headers with
Cache checkpoint information
Updating control files
PMON SMON DBWR LGWR CKPT Others with checkpoint
information

Oracle
Database
Control Files Redo Log Files
Data Files
Archiver (ARCn)
Optional background process
Automatically archives online redo log files when
ARCHIVELOG mode is set
Preserves the record of all changes made to the
database
Oracle
Database
Control Files Redo Log Files Archived Logs
Data Files
ARCn
Oracle Data Storage
Oracle keeps all system and user data in
two basic storage containers:
1. Tablespace a logical entity known only
to Oracle
2. Data Files physical files that may
(typically) be seen from the operating
system
Tablespaces
Can belong to only one database at a time
Consist of one or more data files
Are further divided into logical units of
store
Data Files
Can belong to only one tablespace and
one database
Are a repository for schema object data
Database

Tablespace

Data Data
File File
2 Types of Tablespace
1. Tablespaces required by Oracle for
normal operations
2. Tablespaces that contain data and
indexes that support your applications
Required Tablespaces
System Contains the Oracle Data
Dictionary
Sysaux - New to 10g; supports historic
monitoring / tuning
Temporary Used for disk-based sorting
of data (select...fromorder by)
Undo Used for transaction consistency
during Insert / Update / Delete statements
SQL Statements (IUDS)
Insert What happens when
Update someone connects to
the database and
Delete
issues one of these
Select statements?
Connect to Oracle What Happens
User Server
Process Process
Connect User/Pwd

Are User definition and privileges in SGA


Dictionary Cache?
If not, try to fetch from the System
tablespace
If there, validate Pwd and privileges to login
Allow connection if all is right; otherwise
decline connection
Select What Happens First?
Select *
From MyTab
Order by 1;

Is this statement in the Library Cache?


If statement cached then it has been recently
been parsed and executed
If not cached then parse the statement
If cached then skip parsing stage and execute
statement
Select Parsing the Statement
Select *
From MyTab
Order by 1;

Does MyTab exist?


Does user have Privs to select from
MyTab
What columns are in MyTab
What is the first column in MyTab
Select Executing the Statement
Select *
From MyTab
Order by 1;

Is MyTab data in the SGA Buffer Cache?


If not, fetch data into Buffer Cache
Sort data in MyTab by the first column
If can sort records in memory then do so
If cannot sort in memory then use Temporary
tablespace as disk-based staging area
Return records to client process
I/U/D What Happens First?
Insert (a,b,c)
Into MyTab;

Is this statement in the Library Cache?


If statement cached then it has been recently
been parsed and executed
If not cached then parse the statement
If cached then skip parsing stage and execute
statement
I/U/D Executing the Statement
Insert (a,b,c)
Into MyTab;

Validate values to be inserted


Execute the statement
Keep DB version of the record in Undo
tablespace until Commit or Rollback
Record changes in SGA Redo Log Buffer
Change records in SGA Buffer Cache
DBWn writes changed records to data file(s) as
part of buffer cache management
I/U/D Executing the Statement
Insert (a,b,c)
Into MyTab;
Commit;
or
Rollback;

If Commit then
LGWn writes Redo Log Buffer entries to
Redo Logs
Undo entries are invalidated
If Rollback then
Migrate DB version of record in Undo back to
tablespace/data file
Archivelog Mode
If Instance in Archivelog mode Redo Log
Files are Archived to Archive Logs; which
may be used to recover your database in
the case of disaster

Oracle
Database
Control Files Redo Log Files Archived Logs
Data Files
ARCn
Creating new Database
Managing and Organizing a
Database
Creating a database is the first step in
managing a database system
A database may have been created
automatically as part of Oracle9i Server
installation, or you can create a new one
later
Oracle Data Migration Assistant is used to
migrate from an earlier version of the
database
Creation Prerequisites
To create a new database, you must have
the following:
A privileged account authenticated in one
of the following ways:
By the operating system
Using a password file
Sufficient memory to start the instance
Sufficient disk space for the planned
database
Planning Database File
Locations
Keep at least two active copies of a
database control file on at least two
different devices.
Multiplex the redo log files and put group
members on different disks.
Separate data files whose data:
Will participate in disk resource contention
across different physical disk resources
Have different life spans
Have different administrative characteristics
Creating a Database

An Oracle database can be created using:


Oracle Database Configuration
Assistant
The CREATE DATABASE command
Using the Database Configuration Assistant
The Database Configuration Assistant
allows you to:
Create a database
Configure database options
Delete a database
Manage templates
Create new template using pre-defined
template settings
Create new template from an existing
database
Delete database template
Create a Database
Database Information
Specify:
Global database name and SID
The features you want to use for your database,
such as:
Oracle Spatial
Oracle OLAP Services
Example Schemas
Mode in which you want the database to operate
Dedicated server mode
Shared server mode
Typical or Custom Install
Choose between typical or custom install
Other Parameters
Archive Parameters
Use for database recovery
May also be used for a standby database
Data Block Sizing
Sets the default database block size
Helps to determine the SORT_AREA_SIZE
File Locations
Specify paths for trace files
Specify paths for parameter files
Database storage
Specify storage parameters
Complete Database Creation

Complete database creation using the


following options:
Create database
Save as a database template
Generate database creation scripts
Creating a Database
Manually
Decide on a unique instance and database name
Choose a database character set
Set the operating system variables
Edit / Create the initialization parameter file
Start the instance (nomount)
Execute the CREATE DATABASE command
Run scripts to generate the data dictionary and
accomplish post creation steps
Preparing the Parameter File

Create the new initSID.ora


$$ cp
cp init.ora
init.ora $ORACLE_HOME/dbs/initdb01.ora
$ORACLE_HOME/dbs/initdb01.ora

Modify the initSID.ora by editing


the parameters
Creating SPFILE

Create the SPFILE from initSID.ora


CREATE
CREATE SPFILE
SPFILE FROM
FROM PFILE;
PFILE;
Starting the Instance

Connect as SYSDBA
Start the instance in NOMOUNT stage
STARTUP
STARTUP NOMOUNT
NOMOUNT
Creating the Database
@crdbdb01.sql
@crdbdb01.sql
SQL>
SQL> create
create database
database db01
db01
22 logfile
logfile
33 GROUP
GROUP 11 ('/u01/oradata/db01/log_01_db01.rdo')
('/u01/oradata/db01/log_01_db01.rdo') SIZE
SIZE 15M,
15M,
44 GROUP 2 ('/u01/oradata/db01/log_02_db01.rdo') SIZE 15M,
GROUP 2 ('/u01/oradata/db01/log_02_db01.rdo') SIZE 15M,
55 GROUP
GROUP 33 ('/u01/oradata/db01/log_03_db01.rdo')
('/u01/oradata/db01/log_03_db01.rdo') SIZE
SIZE 15M
15M
66 datafile
datafile '/u01/oradata/db01/system_01_db01.dbf'
'/u01/oradata/db01/system_01_db01.dbf' SIZE
SIZE 100M
100M
77 undo
undo tablespace
tablespace UNDO
UNDO
88 datafile
datafile '/u01/oradata/db01/undo_01_db01.dbf'
'/u01/oradata/db01/undo_01_db01.dbf' SIZE
SIZE 40M
40M
99 default temporary tablespace
default temporary tablespace TEMPTEMP
10
10 tempfile
tempfile '/u01/oradata/db01/temp_01_db01.dbf'
'/u01/oradata/db01/temp_01_db01.dbf' SIZE
SIZE 20M
20M
11
11 extent management local uniform size
extent management local uniform size 128k128k
12
12 character
character set
set AL32UTF8
AL32UTF8
13
13 national
national character
character set
set AL16UTF16
AL16UTF16
14
14 setset time_zone
time_zone == 'America/New_York'
'America/New_York'
15
15 ;;
Creating a Database Using
OMF
Define the OMF initialization parameters in
the
parameter file
DB_CREATE_FILE_DEST
DB_CREATE_ONLINE_DEST_n

STARTUP
STARTUP NOMOUNT
NOMOUNT
CREATE
CREATE DATABASE
DATABASE
DEFAULT
DEFAULT TEMPORARY
TEMPORARY TABLESPACE
TABLESPACE TEMP;
TEMP;
Troubeshooting
Creation of the database fails if:
There are syntax errors in the SQL script
Files that should be created already exist
Operating system errors such as file or
directory permission or insufficient space
errors occur
After Database Creation
The database contains:
Datafiles, control files, and redo log files
User SYS with the password
change_on_install
User SYSTEM with the password
manager
Internal tables (but no data dictionary
views)

You might also like