You are on page 1of 57

2001 Quest Software, Inc.

Oracle vs. DB2 Unix/Windows


Examining Architectural Differences
Jeff Mucher
Sr. Software Consultant
jeff.mucher@quest.com
2001 Quest Software, Inc.
Agenda
! Basic Components & Terminology
! Architectural Layout
! Storage Management
! Logging and Backup/Recovery Options
! Miscellaneous Comparisons
2001 Quest Software, Inc.
Components of DBMS
Oracle
! Instance
! File
! Database
! Tablespace
! Schema
! Table
! Index
! View
! Trigger
! Rollback Segment
! Stored Procs
! SQL Plus
! Roles
DB2 Unix/Windows
! Instance
! Container
! Database
! Tablespace
! Schema
! Table
! Index
! View
! Trigger
! NA
! Stored Procs
! DB2 CLP
! Groups ?
2001 Quest Software, Inc.
Data Types
Oracle
CHAR(N) CHAR(N)
NCHAR(N) NCHAR(N)
VARCHAR2(N) VARCHAR2(N)
NVARCHAR2(N) NVARCHAR2(N)
NUMBER(P,S) NUMBER(P,S)
DATE DATE
RAW(N) RAW(N)
BLOB, CLOB, BLOB, CLOB,
NCLOB, BFILE NCLOB, BFILE
LONG, LONG RAW LONG, LONG RAW
ROWID ROWID
DB2 Unix/Windows
CHAR(n)
VARCHAR(n)
LONG VARCHAR
CLOB
GRAPHIC(n)
VARGRAPHIC(n)
LONG VARGRAPHIC
DBLOB
BLOB (n)
SMALLINT, INTEGER, BIGINT
DECIMAL(p,s), NUMERIC(p,s)
REAL
DOUBLE, FLOAT
DATE
TIME
TIMESTAMP
2001 Quest Software, Inc.
Accessing/Mgmt DB
! OEM - GUI tool set
DBA Mgmt Pack(free)
Change Mgmt Pack
Diagnostics Pack
Tuning Pack
Recovery Manager
! Sqlplus
! Svrmgrl
! Control Center GUI tool set
Command center
Command line processor
Command window
Script center
Visual Explain
! DB2 Command Line
Oracle DB2
2001 Quest Software, Inc.
Product Options
! Personal Edition
! Standard Edition
! Enterprise Edition
! Everyplace
! Satellite Edition
! Personal Edition
! Workgroup Edition
! Enterprise Edition (EE)
! Enterprise Extended
Edition (EEE)
Oracle DB2
2001 Quest Software, Inc.
Common Terms
Different Meanings
Oracle
! Stored Procedure
PL/SQL
! Package
grouping of PL/SQL
blocks
DB2
! Stored Procedure
External - C,Java,Cobol
SQL
! Package
Pre-compiled access plan
2001 Quest Software, Inc.
Different Terms
Similar Meaning
Oracle
! Data Block
! Dictionary
! Alert Log
! Redo Log
! Archive log
! Segments
! Statement Cache
DB2
! Data Page
! Catalog
! Diag log
! Log Files
! Log Retain
! Space Consuming Objects
! Package Cache
2001 Quest Software, Inc.
Instance & Database
Oracle
! Instance Server ID
A collection of Processes
one active databases
Init.ora parameter file
DB2
! Instance db2instance
A collection of Processes
one to many active
databases
Instance (DBM)
Configuration File
Data Base Configuration file
2001 Quest Software, Inc.
Instance
DB2
D
B
M
C
O
N
F
I
G
D
B
M
C
O
N
F
I
G
Instance_1
PRODDB1
Catalog
DBCONFIG
Log
Catalog
Log
DBCONFIG
PRODDB2
BPs
BPs
Instance_2
TESTDB1
Catalog
DBCONFIG
Log
Catalog
Log
DBCONFIG
TESTDB2
BPs
BPs
Password
file
Parameter
file
Archived
log files
Database
Oracle SID
Control
files
Data
files
Redo
log
files
2001 Quest Software, Inc.
Oracle Process Model
2001 Quest Software, Inc.
Oracle SGA
2001 Quest Software, Inc.
Spotlight on Oracle
2001 Quest Software, Inc.
DB2 Process Model
Fenced
UDF
Fenced
DARI
Local
Client Pgm
F
I
R
E
W
A
L
L
db2ipccm
Remote
Listeners
db2resyn
db2sysc
db2wdog
db2gds
Agent Pool
Per
Connection
Processes
Per Database Processes
Media
Writers
Buffer
Manipulators
Backup/Restore
Remote
Client Pgm
db2agent
db2agntp db2agntp
db2agent
db2agntp db2agntp
Per Instance
Processes
db2loggr db2dlock
db2pclnr
db2pfchr
I/O Servers
Bufferpool
Page
Cleaners
Logger Deadlock Detector
2001 Quest Software, Inc.
DB2 Memory
Database Global Memory
dbheap
catalog
cache_sz
Locklist(locklist)
backbufsz
restbufsz
Utility Heap
(util_heap_sz)
Agent Private Memory
logbufsz
rqrioblk rqrioblk
Remote client
aslheapsz
Query
heap
sz
udf_mem_sz
applheapsz
stmtheap
drda_heap_sz
stat_heap_sz
agent_stack_sz
Extended Memory Cache(estore_seg_sz)
Buffer Pools (b u f f p a g e)
pckcachesz
Shared Sort Memory
sortheap
Local client
Application Global Memory
App_ctl_heap_sz
Application
Shared
Memory
Agent /
Application
Shared
Memory
2001 Quest Software, Inc.
Spotlight on DB2
2001 Quest Software, Inc.
System Dictionary/Catalog
! Base tables
SYS.xxxxx$
! System views
SYS.GV_$ or GV$
SYS.V_$ or V$
ALL_
DBA_
USER_
! SYSIBM.xxxx
! SYSCAT
Read-only views defined
for catalog base tables
! SYSSTAT
Updateable set of views
Primarily used for access
path manipulation
Oracle DB2
2001 Quest Software, Inc.
Parallelism
DB2 Enterprise Extended Edition
CPU1 CPU2 CPU3 CPU4
DB
Part 0
DB
Part 1
DB
Part 3
DB
Part 2
Fast Communication Manager
Log Log Log Log Data Data Data Data
9i Real
Application
Cluster (OPS)
2001 Quest Software, Inc.
Types of Parallelism
Oracle
! I/O
! CPU
! Cluster
Intra-cluster
Inter-cluster
! Parallel Query
DB2 EE
! I/O
! CPU
Intra-partition
DB2 EEE
! I/O
! CPU
Intra-partition
Inter-partition
Some options only on partitioned objects
2001 Quest Software, Inc.
Bufferpools
Oracle
! 3 bufferpools available
8i one fixed block (8k)
9i multi block size
! Defined in init.ora
DB_BLOCK_BUFFERS = 20000
DB_BLOCK_LRU_LATCHES = 6
BUFFER_POOL_KEEP =
(BUFFERS:14000,
LRU_LATCHES:1)
BUFFER_POOL_RECYCLE =
(BUFFERS:2000, LRU_LATCHES:3)
! Objects assigned via DDL
DB2
! Defined within a database
4,8,16,32K page
! Main or extended storage
! Defined via DDL
! Tablespaces assigned
2001 Quest Software, Inc.
Databases
Oracle
! A structured collection and
management of information.
! May have more than one for
a SID
! Only one DB
mounted/opened
DB2
! Logical grouping of DB2 objects
! Typically one or two
database/instance
! Catalog for each database
defined within database
SYSCATSPACE
TEMPSPACE
USERSPACE
! Database configuration file
2001 Quest Software, Inc.
Storage Management
! Files
Cooked
Raw
Resize
Auto extend
! Container
Device
Directory
File
Resize
DB2
Oracle
2001 Quest Software, Inc.
Database
Logical Physical
Tablespace Data file
O/S block
Oracle
block
Segment
Extent
Oracle Storage Hierarchy
2001 Quest Software, Inc.
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK6/app04.dbf SIZE 200M
AUTOEXTEND ON NEXT 10M
MAXSIZE 500M;
ALTER TABLESPACE app_data
ADD DATAFILE
/DISK6/app04.dbf SIZE 200M
AUTOEXTEND ON NEXT 10M
MAXSIZE 500M;
Tablespace APP_ DATA Tablespace APP_ DATA
app04.dbf
2M
app03.dbf
2M
app01.dbf
1M
app02.dbf
1M
Oracle Data Files
2001 Quest Software, Inc.
DB2 Containers
! Physical storage device
! A container is assigned to an
individual tablespace
! A TS may have > 1 container
Directory name
SMS Only
D:\MYTS
Raw Device
DMS Only
E:
File name
DMS Only
D:\SODADB\SODA.UTILITY.DMS
SMS
DMS
Directory
/db/payroll/tbsp1/cont
File
Raw Device
2001 Quest Software, Inc.
Tablespaces
! Oracle
Two Categories
System tablespace
Non-System tablespace
Two types of Non-System
Permanent
Temporary
Two types of tablespaces extent management
Dictionary mapped
Locally managed
2001 Quest Software, Inc.
System & Non-System
! System Tablespace
contains:
Data dictionary
information
System rollback
segment
! Non-SYSTEM Tablespace
contains:
Rollback segments
Temporary segments
Application data
Application indexes
2001 Quest Software, Inc.
Tablespace Storage Settings
Oracle
INITIAL
NEXT
MINEXTENTS
MAXEXTENTS
PCTINCREASE
FREELIST & GROUPS
DB2
PAGESIZE
EXTENTSIZE
PREFETCHSIZE
2001 Quest Software, Inc.
Tablespaces
! DB2
Two Categories of Tablespace Management
SMS System Managed Space
DMS Database Managed Space
Three Types of Tablespace
Regular SMS & DMS
Temporary (System & User) SMS & DMS
Long DMS
Three Space Allocation Methods
Directory SMS
File DMS
Device - DMS
2001 Quest Software, Inc.
Tablespaces
! SystemManaged
No finite storage specified
O/Ss file manager
allocates space as
needed
Good for small tables
! Database Managed
Space is pre-allocated
Better suited for large tables
Faster I/O
X
File or Device containers
X
Flexibility of Administration
X
Ease of administration for small
tables
X X
High performance in decision
support
X
High performance in heavy OLTP
X
Space allocated as Needed
X
Separate Indexes fromData
X
Add Containers to TS
SMS DMS
2001 Quest Software, Inc.
Partitioning
Oracle
! Table Definition
1-64k partitions
Partitioning on range,
hash, both or list
Partitions assigned to TS
! Enhances Parallel Query
! Easier Data Management
EEE Only
! Enhances Parallelism
! Easier Data Management
! Nodegroup controls number
of partitions
! Hash key dictates partition
selection within Nodegroup
! TS assigned to Nodegroup
2001 Quest Software, Inc.
DB2 NODEGROUP
! A defined set of Data Partitions
! A tablespace exists within a Nodegroup
More than 1 tablespace can be in a Nodegroup
Rows are distributed across partitions of Nodegroup
Partitioning Map controls data placement
Hash function places rows on a given partition
Data should be evenly distributed across Partitions in
Nodegroup
2001 Quest Software, Inc.
Tables
! Oracle
One to many tables defined in tablespaces
Tables and Indexes are independent of each other
Index Organized Tables
! DB2
One to many tables can be defined within a
tablespace
Indexes directly tied to table definition
2001 Quest Software, Inc.
Indexes
! Oracle
Unique
Non-unique
Partitioning
Function based
Bit Map
! DB2
Unique
Non-unique
Clustering
2001 Quest Software, Inc.
Index entry header
Key column length
Key column value
ROWID
Root
Branch
Leaf
Index entry
Oracle B-Tree Index
2001 Quest Software, Inc.
<Blue, 10.0.3, 12.8.3, 1000100100010010100>
<Green, 10.0.3, 12.8.3, 0001010000100100000>
<Red, 10.0.3, 12.8.3, 0100000011000001001>
<Yellow, 10.0.3, 12.8.3, 0010001000001000010>
key key
start start
ROWID ROWID
end end
ROWID ROWID bitmap bitmap
Table
Index
Block 10
Block 11
Block 12
File 3
Oracle Bitmap Index
2001 Quest Software, Inc.
B-tree
Suitable for high-cardinality
columns
Updates on keys relatively
inexpensive
Inefficient for queries
using OR predicates
Useful for OLTP
Bitmap
Suitable for low-cardinality
columns
Updates to key columns very
expensive
Efficient for queries
using OR predicates
Useful for DSS
Comparing B-Tree and
Bitmap Indexes
2001 Quest Software, Inc.
Indexes
! DB2
Index placement is dependent on table definition.
Tablespace must be specified when table created.
All indexes for a table use same tablespace
Tablespace is predefined before indexes are created
Indexes can be defined in same tablespace as table
2001 Quest Software, Inc.
DB2 Index Structure
F L N
(M,rid)
(N,rid)
(G,rid)
(I,rid)
(K,rid)
(F,rid)
E N Z
Root Node
Data Pages
Intermediate
Nodes
Leaf
Nodes
B-Tree with bi-directional
pointers at Leaf Node
Facilitates reverse scans
2001 Quest Software, Inc.
Logging
! Redo Logs apply to Instance
NoArchive Mode
Full DB recovery
Archive Mode
Recover DB, TS, DF
3 Redo log states
Active
Inactive
Archived
! Redo Logs created in
Groups Number of logs
Members of groups (mirrors)
! Defined at database
Circular
No roll-forward recovery
Log Retain
Fully recoverable
Dual Logs (7.2)
3 log file states
Active
Online Archived
Offline Archived
User exit called for Archiving
ORACLE DB2
2001 Quest Software, Inc.
Group 2
Group 2
Group 3
Group 3
Group 1
Group 1
Member Member
Member Member
Disk 1
Disk 1
Disk 2
Disk 2
Member Member
Member Member
Member Member
Member Member
Redo Log Groups & Members
2001 Quest Software, Inc.
Database
Instance
SGA
CKPT LGWR DBWR
Database
buffer
cache
Control
files
Data files
Redo log
files
Redo log
buffer
ARCH
Parameter
file
Password
file
Archived
log files
Oracle Archive Logging
2001 Quest Software, Inc.
Circular Logging
DB2
! Crash Recovery only
! Log files are reused
! Secondary as needed
! Default method
S
E
C
O
N
D
A
R
Y
1
Primary
1
2 n
3
n
2001 Quest Software, Inc.
Log Retain
! Log files not reused
! Roll Forward Recovery
Online Archival -
Contains information
for committed and
externalized transactions.
Stored in the active log
subdirectory
12
13
14
15
16
Active
Contains information
For non-committed or
Non-externalized
Transactions.
Offline Archival
Files moved from active
Log subdirectory.
Usually offline media
2001 Quest Software, Inc.
Backups
! Database Cold
Offline OS level
All datafiles
All control files
All online redo log files
The init.ora file
! Tablespace Hot
Online OS level
Archive log list
Alter tablespace abc begin backup;
Alter system switch logfile;
Alter database backup controlfile to
'file_name';
! RMAN backup/recovery utility
! Export Database Logical
! Standby Database
! Database Online/Offline
! Tablespace
! Components
Full/Incremental/Delta Copy
DB Configuration
Tablespace definitions
Backup History File
Active/Archive Logs
Oracle DB2
2001 Quest Software, Inc.
Recovery Info
! Control File
Database name
Data file location
Redo log file location
Tablespace names
Current log sequence number
Checkpoint information
Log history
Backup information
! RMAN - Recovery Catalog
Recovery History File
! Updated:
Backup of DB/TS
Restore/Roll Forward of DB/TS
Drop/Load/Reorg/Stats of a table
Quiesce/Alter TS
! Contains
Part of DB which was copied
When DB was copied
Location of the copy
Time of last restore
DDL of tables
Oracle
DB2
2001 Quest Software, Inc.
Types of Recovery
! Instance Recovery
Uses Redo logs to recover from
System/Instance failures
! NoArchive Mode
Full Database (cold)
! Archive Mode
Point in time
Automatic
! Import (logical)
! Crash
Uses logs to recover from
System/Instance failures
! Version (non-recoverable DB)
Image copy (TOCOPY)
! Roll-Forward
Image copy plus log apply
! Import/Load (logical)
Oracle DB2
2001 Quest Software, Inc.
Utilities
! IMPORT
! EXPORT
! SQL*LOADER
! ANALYZE
! DB_VERIFY
! RMAN
! BACKUP
! IMPORT
! EXPORT
! LOAD
! RESTORE
! REORG (Table)
! REORGCHK
! RUNSTATS
Oracle DB2
2001 Quest Software, Inc.
Reorganizing Data
! Import
! Export
! Table only within DB
! REORGCHK
Determines when Reorg is
required
Oracle
DB2
2001 Quest Software, Inc.
Loading Data
! SQL*Loader Utility
Insert/Append/Replace/Truncate
Direct=True|False
By-pass SGA build data block
No Triggers
No RI
Parallel=True|False
Multiple load files
Drop all Indexes
Recoverable/Unrecoverable
! Load
Insert/Replace
RUNSTATS
Usually faster than import
Good for large amounts of data
No Triggers/RI
! Import
Can dynamically create table
Insert process
Update
Replace
Good for small amounts of data
Oracle
DB2
2001 Quest Software, Inc.
DB2 Import vs. Load
Cannot load into host databases. Load
utility not usable with Connect
Ability to import into host databases with
Connect
Statistics can be gathered during the load Up to date statistics are required,
RUNSTATS needs to be executed
Indexes are built after the data has been
loaded and keys sorted
Keys of each roware inserted into the index
one at a time during import
Unique constraints are validated during
load. All other constraints must be checked
by the Set Constraints command
All constraints are validated during import
Triggers are not supported Triggers will be fired
Tablespace(s) containing table and indexes
are offline for duration of load
Tablespace(s) containing table and indexes
are online for duration of import
Can import into tables only Can import into tables, views, and aliases
WSF format not supported WSF format support
Table & indexes must exist Creation of table & IXs supported with IXF
IMPORT LOAD
2001 Quest Software, Inc.
Optimizer
Oracle
! Rules - Hints
! Cost based
! Choose
DB2
! Cost based more
sophisticated than Oracle
Seven levels of
optimization
Adjusted based on query
complexity
! No Rules
2001 Quest Software, Inc.
Optimization Class
Guidelines
Recommendation Level
Used to determine whether more comprehensive optimization can generate
better access plan for very complex long running queries using large tables
9
Same as 5 except optimization not reduced for complex dynamic SQL 7
DEFAULT Most cost effective method for mix of simple and complex queries.
Optimization will be automatically reduced for complex dynamic SQL if
optimizer determines that the resources are not necessary.
5
Closest to Oracle optimizer. Recommended for queries with 4 or more joins. 3
Recommended for very complex queries which are infrequently executed in a
decision support or OLAP environment.
2
Similar to 0 except Merge Scan and TS scan enabled.
1
Minimal amount of optimization. Only recommended for very simple SQL
accessing well indexed tables. Only nested loop joins and IX scans enabled.
0
2001 Quest Software, Inc.
EXPLAIN
EXPLAIN_INSTANCE
EXPLAIN_STATEMENT
EXPLAIN_OPERATOR
EXPLAIN_STREAM
EXPLAIN_OBJECT
EXPLAIN_ARGUMENT EXPLAIN_PREDICATE
Oracle
DB2
PLAN_TABLE
2001 Quest Software, Inc.
Monitoring
! Performance Snapshots -V$
Instance/Database
Memory
Disk
User/Session
Contention
! UTLBSTAT and UTLESTAT
Collects Stats over time
! TKPROF
Formats SQL trace data from
applications
! Snapshot Monitor
Show status of database counters
at instant in time
Buff, Lock, Sort, Stmt, Tbl, UOW
! Event Monitor
Status after the event
Databases
Tablespaces
Connections
Tables
Statements
Transactions
Deadlocks
DB2 Oracle
2001 Quest Software, Inc.
Summary
To be a successful cross platform DBA:
! Have a sound foundation of relational principles
! Understand the nuances of the individual platforms
! Understand that the principles of database administration are
similar regardless of the RDMS
2001 Quest Software, Inc.