You are on page 1of 61

Oracle vs.

DB2 Unix/Windows
Examining Architectural Differences

Presented by Jeff Mucher, Systems Consultant Manager jeff.mucher@quest.com

2001 Quest Software, Inc.

Agenda
Basic Components and terminology Architectural layout Storage management Logging and backup/recovery options Miscellaneous comparisons Summary

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) NCHAR(N) VARCHAR2(N) NVARCHAR2(N) NUMBER(P,S) DATE RAW(N) BLOB, CLOB, NCLOB, BFILE LONG, LONG RAW 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
Oracle
OEM - GUI tool set DBA Mgmt Pack(free) Change Mgmt Pack Diagnostics Pack Tuning Pack Recovery Manager Sqlplus Svrmgrl (pre 9i)

DB2
Control Center GUI tool set Command center Command line processor Command window Script center Visual Explain DB2 Command Line

2001 Quest Software, Inc.

Product Options
Oracle
Personal Edition Standard Edition Enterprise Edition Real App Cluster

DB2
Personal Edition => PE Workgroup Edition => WSE Enterprise Edition (EE) => ESE Enterprise Extended Edition (EEE) => ESE (partition feature)

2001 Quest Software, Inc.

Common Terms Different Meanings


Oracle
Stored Procedure PL/SQL Package grouping of PL/SQL blocks Package body

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 and 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 DB2SET Registry Variables

2001 Quest Software, Inc.

Instance
Oracle SID
Parameter file

DB2
D B M C O N F I G D B M C O N F I G

Instance_1
Catalog

Control files

PRODDB1
Log

DBCONFIG BPs

Catalog Log

PRODDB2

DBCONFIG BPs

Password file

Archived log files

Data files

Redo log files

Instance_2
Catalog

TESTDB1
Log

DBCONFIG BPs

Database

Catalog Log

TESTDB2

DBCONFIG BPs

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


F
Fenced UDF Fenced DARI Local Client Pgm db2gds db2wdog db2sysc db2resyn db2ipccm db2agent
db2agntp db2agntp

I R E W A

Per Connection Processes

Per Database Processes

db2pfchr db2pclnr db2loggr


Logger

I/O Servers Bufferpool Page Cleaners

db2dlock
Deadlock Detector

db2agent Remote Listeners


Per Instance Processes
db2agntp db2agntp

Backup/Restore

Remote Client Pgm

L L

Agent Pool
2001 Quest Software, Inc.

Media Writers

Buffer Manipulators

DB2 Memory
Database Global Memory
Utility Heap (util_heap_sz)
backbufsz restbufsz

dbheap
logbufsz catalog cache_sz pckcachesz

Buffer Pools (b u f f p a g e)
Extended Memory Cache(estore_seg_sz)

Locklist(locklist) Shared Sort Memory Application Global Memory


App_ctl_heap_sz

Local client Agent / Application Shared Memory

Remote client Application Shared Memory

Agent Private Memory


applheapsz Query heap sz stmtheap stat_heap_sz agent_stack_sz rqrioblk

aslheapsz

rqrioblk

2001 Quest Software, Inc. sortheap drda_heap_sz udf_mem_sz

Spotlight on DB2

2001 Quest Software, Inc.

System Dictionary/Catalog
Oracle
Base tables SYS.xxxxx$ System views SYS.GV_$ or GV$ SYS.V_$ or V$ ALL_ DBA_ USER_

DB2
SYSIBM.xxxx SYSCAT Read-only views defined for catalog base tables SYSSTAT Updateable set of views Primarily used for access path manipulation

2001 Quest Software, Inc.

Parallelism
9i Real Application Cluster (OPS) DB2 Enterprise Extended Edition
Fast Communication Manager

CPU1 DB Part 0
Log Data Log

CPU2 DB Part 1
Data Log

CPU3 DB Part 2
Data Log

CPU4 DB Part 3
Data

2001 Quest Software, Inc.

Types of Parallelism
Oracle
I/O CPU Cluster Intra-cluster Inter-cluster Parallel Query

DB2 EE

DB2 EEE

I/O I/O CPU CPU Intra-partition 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)

DB2
Defined within a database 4,8,16,32K page Main or extended storage Defined via DDL (Dynamic V8) Tablespaces assigned

Objects assigned via DDL


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.

Oracle Storage Hierarchy


Database

Tablespace

Data file

Logical Segment
Extent Oracle 2001 Quest Software, Inc. block

Physical

O/S block

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 and Non-System


System Non-System tablespace contains: tablespace contains:
Data dictionary information System rollback segment 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.

DB2 Storage Hierarchy


Database

Tablespace

Container

Logical

Object Extent DB2 Page

Physical

2001 Quest Software, Inc.

O/S block

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
SMS DMS

System managed
No finite storage specified O/Ss file manager allocates space as needed Good for small tables

Add Containers to TS Separate Indexes from Data Space allocated as Needed High performance in heavy OLTP High performance in decision support Ease of administration for small tables Flexibility of Administration File or Device containers

X X X X X X X X X

Database managed
Space is pre-allocated Better suited for large tables Faster I/O

2001 Quest Software, Inc.

Storage Management
Oracle
Files
Cooked Raw Resize Auto extend

DB2
Container
Device Directory File Resize

2001 Quest Software, Inc.

Oracle Data Files


ALTER ALTER TABLESPACE TABLESPACE app_data app_data ADD ADD DATAFILE DATAFILE /DISK6/app04.dbf /DISK6/app04.dbf SIZE SIZE 200M 200M AUTOEXTEND AUTOEXTEND ON ON NEXT NEXT 10M 10M MAXSIZE MAXSIZE 500M; 500M;
Tablespace APP_ DATA
app01.dbf 1M app02.dbf 1M app03.dbf 2M app04.dbf 2M

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
Directory

/db/payroll/tbsp1/cont

File

DMS

Raw Device

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 a tablespace Tables and indexes are independent of each other Index organized tables

DB2
One to many tables defined in 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 Multidimensional clustering (V8)

2001 Quest Software, Inc.

Oracle B-Tree Index


Index entry Root

Branch

Index entry header Leaf Key column length Key column value ROWID
2001 Quest Software, Inc.

Oracle Bitmap Index


Table
File 3 Block 10 Block 11

Index

Block 12

key
<Blue, <Green, <Red, <Yellow,

start end ROWID ROWID


10.0.3, 10.0.3, 10.0.3, 10.0.3, 12.8.3, 12.8.3, 12.8.3, 12.8.3,

bitmap
1000100100010010100> 0001010000100100000> 0100000011000001001> 0010001000001000010>

2001 Quest Software, Inc.

Comparing B-Tree and Bitmap Indexes


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
2001 Quest Software, Inc.

Indexes
DB2
Index placement is dependent on table definition Tablespace must be specified when table is 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


B-Tree with bi-directional pointers at Leaf Node Facilitates reverse scans
Root Node
E N Z Intermediate Nodes F L N

(F,rid)

(G,rid) (I,rid) (K,rid)

(M,rid) (N,rid)

Leaf Nodes

Data Pages
2001 Quest Software, Inc.

Logging
Oracle
Redo Logs apply to Instance NoArchive Mode
Full DB recovery

DB2
Defined at database Circular
No roll-forward recovery

Archive Mode
Recover DB, TS, DF, block 3 redo log states Active Inactive Archived

Log Retain
Fully recoverable Dual logs (7.2) 3 log file states Active Online Archived Offline Archived User exit called for archiving

Redo Logs created in Groups Number of logs Members of groups (mirrors) Rollback segments
2001 Quest Software, Inc.

Redo Log Groups and Members


Group 1
Member

Group 2
Member

Group 3
Member

Disk 1

Member

Member

Member

Disk 2

2001 Quest Software, Inc.

Oracle Archive Logging


Instance SGA
Database buffer cache Redo log buffer

DBWR

CKPT

LGWR

ARCH

Control files Parameter file Password file Data files Archived log files

Redo log files

2001 Quest Software, Inc.

Database

Rollback Segment
Old image

Table Rollback Segment

New image

Update transaction

Rollback Segments: Purpose

Transaction rollback

Transaction recovery

Rollback segment

Read consistency

Read-Consistency
Table SELECT * FROM table

New image Image at statement commencement

Circular Logging
DB2
Crash Recovery only Log files are reused Secondary as needed Default method

1 n
Primary

3 n

S E C O N D A R Y

2001 Quest Software, Inc.

Log Retain
Log files not reused Roll Forward Recovery
12 13

Online Archival Contains information for committed and externalized transactions. Stored in the active log subdirectory

14
Offline Archival Files moved from active Log subdirectory. Usually offline media

15
Active Contains information For non-committed or non-externalized Transactions.

16

2001 Quest Software, Inc.

Backups
Oracle
Database Cold Offline OS level
All datafiles All control files All online redo log files The init.ora file

DB2
Database Online/Offline Tablespace Components Full/Incremental/Delt a Copy DB Configuration Tablespace definitions Backup History File Active/Archive Logs Recovery Expert

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


2001 Quest Software, Inc.

Recovery Info
Oracle
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

DB2
Recovery history File Updated: Backup of DB/TS Restore/Roll Forward of DB/TS Drop/Load/Reorg/Sta ts 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

2001 Quest Software, Inc.

Types of Recovery
Oracle DB2
Crash Uses logs to recover from system/instance failures Version Image copy (TOCOPY) Roll-Forward Image copy plus log apply Import/Load (logical) Instance recovery Uses redo logs to recover from system/instance failures NoArchive mode Full database (cold) Archive mode Point in time Automatic Import (logical)

2001 Quest Software, Inc.

Utilities
Oracle
IMPORT EXPORT SQL*LOADER ANALYZE DB_VERIFY RMAN

DB2
BACKUP IMPORT EXPORT LOAD RESTORE REORG (online V8) REORGCHK RUNSTATS Unload (V8)

2001 Quest Software, Inc.

Reorganizing Data
Oracle
Import Export Alter table move

DB2
REORG Table Index (v8) REORGCHK Determines when Reorg is required

2001 Quest Software, Inc.

Loading Data
Oracle DB2
Load SQL*Loader Utility Insert/Replace Insert/Append/ RUNSTATS Replace/Truncate Usually faster than import Direct=True|False Good for large amounts of By-pass SGA build data block data No Triggers No Triggers/RI No RI Import Parallel=True|False Can dynamically create table Multiple load files Insert process Drop all Indexes Recoverable/Unrecoverable
Update Replace

Good for small amounts of data


2001 Quest Software, Inc.

DB2 Import vs. Load


IMPORT
Creation of table & IXs supported with IXF WSF format support Can import into tables, views, and aliases Tablespace(s) containing table and indexes are online for duration of import Triggers will be fired All constraints are validated during import

LOAD
Table & indexes must exist WSF format not supported Can import into tables only Tablespace(s) containing table and indexes are offline for duration of load Triggers are not supported Unique constraints are validated during load. All other constraints must be checked by the Set Constraints command. Indexes are built after the data has been loaded and keys sorted. V7 Incremental Index. Statistics can be gathered during the load Cannot load into host databases. Load utility not usable with Connect.

Keys of each row are inserted into the index one at a time during import Up to date statistics are required, RUNSTATS needs to be executed Ability to import into host databases with Connect

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


Level 0 Recommendation Minimal amount of optimization. Only recommended for very simple SQL accessing well indexed tables. Only nested loop joins and IX scans enabled. Similar to 0 except Merge Scan and TS scan enabled. Recommended for very complex queries which are infrequently executed in a decision support or OLAP environment. Closest to DB2/390 optimizer. Recommended for queries with 4 or more joins. 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. Same as 5 except optimization not reduced for complex dynamic SQL Used to determine whether more comprehensive optimization can generate better access plan for very complex long running queries using large tables

1 2 3 5

7 9

2001 Quest Software, Inc.

EXPLAIN
Oracle
PLAN_TABLE EXPLAIN_STATEMENT

DB2
EXPLAIN_INSTANCE

EXPLAIN_OPERATOR

EXPLAIN_PREDICATE

EXPLAIN_STREAM

EXPLAIN_ARGUMENT

EXPLAIN_OBJECT

2001 Quest Software, Inc.

Monitoring
Oracle
Performance snapshots - V$ Instance/database Memory Disk User/session Contention StatsPack Collects Stats over time TKPROF Formats SQL trace data from applications

DB2
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

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.

QUESTIONS & ANSWERS

2001 Quest Software, Inc.

You might also like