2008 2086 gangler

50
Mike Gangler Ithaka / JStor Session # 2086 2086/Migrating SQL Server 2005 Applications to Oracle

Upload: mike-gangler

Post on 16-Jan-2015

588 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 2008 2086 Gangler

Mike Gangler

Ithaka / JStor

Session #

2086

2086/Migrating SQL Server 2005

Applications to Oracle

Page 2: 2008 2086 Gangler

Speaker and Company Information

• Database Specialist with JSTOR – www.jstor.org

• 20+ Years DBA experience

• Presented Collaborate in ’07, SEMOP, Regional user Groups and at many IOUG-Alive events

• Experience with FOCUS, IMS DB/DC, DB2, Sybase, and MSSQL 6.5 databases prior to assignment.

• JSTOR - is a not-for-profit organization dedicated to helping the scholarly community discover, use, and build upon a wide range of intellectual content in a trusted digital archive. We collaborate

with organizations that benefit the scholarly community.

Page 3: 2008 2086 Gangler

Agenda

• Introduction

• Overview of Problem

• Basic and Fundamental Differences

• Database Locking

• Data Objects

• Data Types

• Data Access – DML and Examples

Page 4: 2008 2086 Gangler

Introduction

• This session will describe the lessons learned during the process of converting an MSSQL database application to Oracle.

• Session targeted towards Oracle DBA’s with little or no MSSQL experience.

• JSTOR purchased a 3rd party product that was using primarily MSSQL.

• Agreement was that JSTOR would convert MSSQL patches and coding to Oracle (If and when needed).

• Project started in 2006 and we launched the new product in April 2008.

• Using Oracle 10G release 2 and Grid Control on Sun Solaris X86-64 machines

• 3rd Party using SQL Server 2005

Page 5: 2008 2086 Gangler

Overview of Problem

• JSTOR Is primarily a Oracle Shop

• 3rd Party is primarily a MSSQL Shop

• Coding was supposed to be “Database Agnostic”

• Limited assistance from 3rd Party

• Limited experience with MSSQL

• 2 development centers – Santa Clara and Ann Arbor– code control

– version control

– little or no communication

• 3 – 5 patches a day

Page 6: 2008 2086 Gangler

Basic and Fundamental Differences

• Database, Instance and Storage Architecture

– Terminology

– Characteristic Differences

– Comparison of Core Objects

– Storage Architecture

– Data Blocks, Extents and Segments

– Memory Address Space – Oracle

– Memory Address Space – MSSQL

– Process and Thread-based Architecture

– Background Processes

Page 7: 2008 2086 Gangler

Basic and Fundamental Differences -

Database and Instance

• Terminology –

– Oracle Instance = Memory and Processes related

to a Database.

– Oracle Database = Files containing application

and system information

– MSSQL Instance = set of binaries isolating the

SQL Server database Engine Services.

• Every Instance will have its own system database and separate Admin parms.

– MSSQL Database = Oracle schema with a Master DB (System Tables).

Page 8: 2008 2086 Gangler

Basic and Fundamental Differences –

Database and Instance

32K File Groups65KMax # of tablespaces

32TB64 GbMax log file size

50Based on Server Resources

Instances Per Server

1EB4PBMaximum DB Size

8KB16KBMaximum Block Size

2 Million Blocks4 Million blocksMaximum Blocks Per File

32K65KMaximum # of Files

32K File Groups65KMax # of tablespaces

16TB64GbMaximum File Size

8KB2KBMinimum Block Size

SQL ServerOracle Characteristic

Page 9: 2008 2086 Gangler

Basic and Fundamental Differences –

Comparison of Core Objects

XML Schema CollectionXMLDB

N/APackage

Service Broker QueueStreams

FunctionFunction

Stored ProcedureProcedure

IndexIndex

ViewView

N/ASequence

TypeObject Type

SynonymSynonym

TableTable

SQL ServerOracle

Page 10: 2008 2086 Gangler

Basic and Fundamental Differences – Storage

Architecture

• Physical

– Oracle Data file = MSSQL data file or Device

• Logical

– Oracle tablespace = MSSQL File Group

– Oracle Segment = MSSQL Heap/Index

– Oracle Extent = MSSQL Extent

– Oracle Blocks = MSSQL Pages

Page 11: 2008 2086 Gangler

Basic and Fundamental Differences –Data

Blocks, Extents and segments

• Smallest unit of logical storage

– Oracle = Block

– MSSQL = Page

• Block size

– Oracle is variable

– MSSQL is fixed at 8kb

• Extent size

– Oracle is variable

– MSSQL are fixed at 64kb

Page 12: 2008 2086 Gangler

Basic and Fundamental Differences –Memory

Address Space - Oracle

• Memory Allocation Concepts – Oracle

– Oracle is static

– Allocated at Startup

– MSSQL is Dynamic

– Variables set by administrator

– ASSM introduced in Oracle 10g

Page 13: 2008 2086 Gangler

Basic and Fundamental Differences –Memory

Address Space – MSSQL 2005

• Memory Allocation Concepts – MSSQL 2005

– Allocations are constantly changed based on RDBMS needs and operating system needs (Self Tuning).

– Allocation is dynamic at higher level (Memory pool, etc.) and lower level ( Buffer cache, procedure cache, etc.) components.

– Very Few configurable parameters

– Min server memory and max server memory settings

• Memory address range

– Leveraging Address Windowing Extensions (AWE)

Page 14: 2008 2086 Gangler

Basic and Fundamental Differences –Process

and Thread-based Architecture

• Process is an independent piece of code with its own memory space

• Thread is spawned by a process and works within the parents memory space

• Advantages of using Threads:

– Reduced overhead in context switching and reduction in overall memory requirements

– Microsoft fibers are light-weight threads further reduces context switching overheads by running purely in user mode

• Oracle uses processes in Unix and Threads in Windows

• Both Oracle and SQL Server use threads and optionally fibers. Threads/fibers are scheduled onto a CPU by a user mode Scheduler(UMS)

• Process/thread can be tied to processors in both Oracle (Windows) and SQL Server 2005 using CPU affinity feature.

Page 15: 2008 2086 Gangler

Basic and Fundamental Differences –

Background Processes

OptionalMS DTCRECORecoverer

MandatoryLazywriterDBWnDB Writers

MandatoryDatabase

Checkpoint

CKPTCheckpoint

Processes

MandatoryLog WriterLGWRLogwriter

MandatoryDatabase

Cleanups and

Shrinking

SMONSystem

Monitor

MandatorySQLOSPMONProcess

monitor

requiredSQL Server Oracle IDOracle

Processes

Page 16: 2008 2086 Gangler

Basic and Fundamental Differences –

Background Processes

N/AN/AARCnArchive

MandatoryNetworker Threads

DnnnDispatcher

MandatoryWorker Threads

SnnnShared Servers

OptionalWorker Threads

PnnnParallel Slave processes

MandatorySQL AgentJnnnJob Queue Process

requiredSQL Server Oracle IDOracle Processes

Page 17: 2008 2086 Gangler

Database Locking

• MSSQL – Prior to SQLSERVER 2005– Select statements obtain shared locks on

pages/rows.• Prevents other statements from obtaining an exclusive

lock on those pages/rows.

• All Update statements require exclusive lock.

• These locks will lock all update transactions until the select commits or roll backs.

• transactions are physically serialized whenever 1 transaction selects the data and 1 changes.

• ORACLE –– Readers don’t block writers and writers don’t

block readers.

Page 18: 2008 2086 Gangler

Database Locking – Row Vs Page

• MSSQL

– Prior to MSSQL 2005 no row level locking

– Does page level locking, which blocks all rows on

the page.

– MSSQL2005 – does a form of row level locking.

– MSSQL2005 – Escalates locks at row level to

page level automatically.

• ORACLE

– Row level locking

– Only one row is locked when DML is changing the

row.

Page 19: 2008 2086 Gangler

Data Objects

Clustered IndexIndexed-Organized Table

Table VariableObject Table

** Linked Server FeatureExternal Table

Temporary TableTemporary Table

N/ANested Table

N/APartitioned Table

N/AClustered Table

HeapHeap-Organized Table

SQL ServerOracle

Page 20: 2008 2086 Gangler

Data Objects - Table

• Heap is the default Form of data organization in a table, where data is stored in an unordered manner

• In Oracle, Index Organized Tables store data in a B-Tree structure in primary key order.

• SQL Server offers clustered indexes where data can be ordered by any column

• Oracle and MSSQL offer local and global temporary tables to store transient application data

Page 21: 2008 2086 Gangler

Data Objects – Indexes (Diff)

NoYesBitmap Join

NoYesBitmap

NoYesB-Tree Partition

Yes (Clustered)YesB-Tree IOT

NoYesB-Tree Function Based

NoYesB-Tree Key Compressed

NoYesB-Tree Reverse

Yes (16 Cols)Yes (32 Cols)B-tree Composite

MSSQLOracleIndex Scheme

Page 22: 2008 2086 Gangler

Data Objects – Views (Diff)

YesNoIndexed Views

NoYesObject Views

MSSQLOracleView Type

INLINE Views – MSSQL use Derived tables and CTE

(Common table Expressions)

Updateable Views – Restrictions in MSSQL can be bypassed by defining a “INSTEAD OF” trigger on the

view.

Page 23: 2008 2086 Gangler

Data Types – Character Based

2GBImage 4GBBLOB

2GBNText4GBNCLOB

2GBText4GBCLOB

2GBText1 – 2GbLONG

1 - 8000Nvarchar1 – 4000NVarchar2

1 - 8000Varchar1 – 4000Varchar2

1 - 8000NVarchar1 – 4000NVarchar

1 - 8000Varchar1 – 4000Varchar

1 – 4000NChar1 – 2000NChar

1 - 8000Char1 – 2000Char

SQL SizeSQL TypeOracle SizeOracle Type

Page 24: 2008 2086 Gangler

Data Types – Numeric Data

Small MoneyNumber(10,4)

MoneyNumber(19,4)

BitNumber(1)

FloatFloat / Number(38)

Numeric(p,s)Number(p,0)

decimalNumber(p,0)

tinyintNumber(3,0)

smallintSmallint /

Number(6,0)

intInt / Number(10,0)

BigintNumber(19,0)

SQL TypeOracle Type

Page 25: 2008 2086 Gangler

Data Types – Other Types

FLOATREAL

FLOATFLOAT

VARBINARY(n)RAW(n) / BLOB

Binary(n)RAW(n) / BLOB

datetimeTimestamp

SmalldatetimeDate

datetimeDate

SQL TypeOracle Type

Page 26: 2008 2086 Gangler

Date Data Types

• MSSQL datetime accurate up to 3.33 Milliseconds.

• Oracle “date” is accurate up to 1 second.

• Oracle’s timestamp up to 1 Millisecond.

• MSSQL “smalldatetime” up to 1 Minute.

• If application requires sub second Date Precision use Oracle’s “timestamp”.

• MSSQL “timestamp” not related to “datetime”

– MSSQL2005 – “timestamp” = SQL2000 –

“rowversion.

– It's a unique value which is changed every time

the row is updated

Page 27: 2008 2086 Gangler

Data Access – DML and Examples

Select * from table where rownum <=5

Select top 5 from table

Select lastname||’,’||firstname from …

Select lastname +’,’+firstname from ….

Select lastname “Last Name”from …. Or

Select lastname as ‘last name’from ….

Select ‘last Name’=lastname from ….

Select sqrt(100) from dualSelect sqrt(100)

Semi Colon (;)GO

OracleMSSQL

Page 28: 2008 2086 Gangler

Data Access – DML and examples

n/a – procedure to emulate the sp_rename function.

Sp_rename

Create or replace procedureCreate procedure

Select 3+5 from dualSelect 3+5 (from not required)

Select sysdate from dualSelect getdate()

Case or decodeCase

NVL(exp,val)ISNULL(EXP,VAL)

caseNullif(exp,exp)

Where ta.col(+) = tb.colLeft outer Join

OracleMSSQL

Page 29: 2008 2086 Gangler

Select clause Differences

• MSSQL

– “TOP”

– “IDENTITYCOL”

– “ROWGUIDCOL”

– Column Alias – select c1 = ‘alias’ from t1

• ORACLE

– Select c1 from t1 where rownum < n

– Doesn’t support “identitycol”

– Doesn’t support “rowguidcol” (sys_guid)

– Column alias – select c1 “alias’ from t1

Page 30: 2008 2086 Gangler

Update Statements

• MSSQL

– Supports a “FROM” clause

– MSSQL Example:

• Update t1 set col1=0 from t1=a, t2=b where a.c2 = b.c2

• ORACLE

– Doesn’t Support a “FROM” clause

– Oracle Example:

• Update t1 set col1=0 where col1 in (select col1 from t2 where c3 = ‘USA’)

Page 31: 2008 2086 Gangler

Delete Statements

• MSSQL

– Supports a “FROM” clause

– MSSQL Example:

• Delete tableA from tableA a, tableB b where a.c1 = b.c1

• ORACLE

– Doesn’t Support a “FROM” clause

– Oracle Example:

• Delete tableA a

• Where exists (select * from tableB b where a.c1 = b.c1)

Page 32: 2008 2086 Gangler

“Into” Clause

• MSSQL

– Select * into t1 from t2

– Insert * into t1 from t2

• ORACLE

– Create table t1 as select * from t2

– Insert into t1 as select * from t2

Page 33: 2008 2086 Gangler

Global Tables Examples

• MSSQL

Create table #a_temp_table (col1 INT, col2 char(1))

• OracleCreate global temporary table

tt_a_temp_table (col1 number(6), col2 char(1))

On commit reserve rows

Page 34: 2008 2086 Gangler

Empty String Literals

• MSSQL – interprets empty string as a single

blank space

• Oracle – interprets empty string as NULL

• MSSQL

– Insert into table (c1, c2) values (‘foo’,’’)

– Select c1 from table where c1 = ‘’

• Oracle

– Insert into table (c1,c2) values ‘foo’, ‘ ‘)

– Select c1 from table where c1 = ‘ ‘

Page 35: 2008 2086 Gangler

Remote Objects

• MSSQL– Server_name.database_name.object_owner.object_name

– Example:

• Sqlserver1.sales.ny.acme.com.scott.emp

• ORACLE– Object_owner.object_name@database_name

– Example

[email protected]

Page 36: 2008 2086 Gangler

Operators

>=all>=ALL or !<allGreater than or equal

to every member of the

set

<=all<=ALL or !>allLess than or equal to

every member of the

set

=SOME or ININ or =ANYEqual to a member of a

set

Like ‘a%’

or LIKE ‘a\%’

Like ‘a%’ or LIKE’a[x-z]’Pattern matches

>=>= or !<Greater than or equal

to

<=<= or !>Less than or equal to

OracleMSSQLOperator

Page 37: 2008 2086 Gangler

Functions

USERSESSION_USER

CASENULLIF

NVLISNULL

N/AIsdate

Userenv(‘host’)Host_name

Userenv(‘terminal’)Host_id

LengthDatalength

userCurrent_user

sysdateCurrent_timestamp

OracleMSSQL

Page 38: 2008 2086 Gangler

STRING Functions

N/AUNICODE

TO_CHARStr

RPAD(‘ ‘,’N-1,’ ‘)SPACE(N)

SUBSTR(STR,-(N))REPLICATE(STR,)

N/ANCHAR

LTRIMLTRIM

SUBSTR(STR,1,N)LEFT(STR,N)

INSTRCHARINDEX

CHRCHAR

OracleMSSQL

Page 39: 2008 2086 Gangler

Easy T-SQL example - MSSQL

Create proc proc1

As

Begin

Declare @x int

If exists (select * from table2)

Select @x = -1

end

Page 40: 2008 2086 Gangler

Easy T-SQL example - ORACLE

Create or replace procedure proc1

As

V_x number(10);

V_temp number(1,0) := 0;

Begin

Select 1 into v_temp

From dual

where exists (select * from table2);

If v_temp = 1 then

V_x := -1;

End if;

End;

Page 41: 2008 2086 Gangler

T/SQL – Example - MSSQL

UPDATE admin_role SET template ='<?xml version="1.0" encoding="UTF-8"?><templates>

<package id="identity"><action name="read"></action>

</package><package id="metadata">

<action name="read"></action></package><package id="ecommerce">

<action name="access"></action></package><package id="redirect">

<action name="read"></action><action name="change"></action><action name="create"></action><action name="delete"></action>

</package>…. **** Greater than 4000 Bytes<backstage action="adminBackstage-setPriority" area="6"></backstage>

<backstage action="adminBackstage-changeSubjHeading" area="6"></backstage></templates>'

WHERE name = 'Publisher Super Admin'

Page 42: 2008 2086 Gangler

T/SQL Conversion Example - Oracle

declare

template_lob2 clob;

begin

template_lob2 :='<?xml version="1.0" encoding="UTF-8"?>

<templates>

<package id="identity">

<action name="read"></action>

<action name="change"></action>

<action name="create"></action>

<action name="delete"></action>

<action name="changepwd"></action>

<action name="settings"></action>

<action name="impersonate"/>

</package>…….*** Greater than 4000 Bytes

<backstage action="adminBackstage-changeSubjHeading" area="6"></backstage>

</templates>';

UPDATE admin_role set template=template_lob2 WHERE name = 'Publisher Super Admin';

Page 43: 2008 2086 Gangler

Case example - MSSQL

update PUBLICATION

set Area = (select CASE

WHEN Area LIKE '00000000%' THEN 0

WHEN Area LIKE '00000001%' THEN 1

WHEN Area LIKE '00000010%' THEN 2

WHEN Area LIKE '00000100%' THEN 4

WHEN Area LIKE '00001000%' THEN 8

WHEN Area LIKE '00010000%' THEN 16

WHEN Area LIKE '00100000%' THEN 32

WHEN Area LIKE '01000000%' THEN 64

WHEN Area LIKE '10000000%' THEN 128

END

from PUB_AREA_STR_BACKUP

where PUBLICATION.pubid = PUB_AREA_STR_BACKUP.pubid)

where pubid in (select pubid from PUB_AREA_STR_BACKUP);

Page 44: 2008 2086 Gangler

Case example - Oracle

update PUBLICATION set Area =

(select decode(Area, '0000000000000000', 0,

'0000000100000000', 1,

'0000001000000000', 2,

'0000100000000000', 8,

'0001000000000000', 16,

'0010000000000000', 32)

from article_meta where article_meta.articleid = PUBLICATION.PubId)

where exists (select articleId from article_meta where PUBLICATION.pubid = article_meta.articleid and area is not null and area <> '0000010000000000');

Page 45: 2008 2086 Gangler

Sequence Differences

• MSSQL

– No Database Sequences

– Example –

CREATE TABLE SEQ_OFFERID_SEQ ( idvalue bigint IDENTITY(1,1) )

• T-SQL Example:declare @uid bigint

exec nextval2 'UserID_SEQ', @uid output

insert into change_record (userid, createupdatedate, action, sessionid, userid)

values (@uid, getdate(), 0, -1, -1)

Page 46: 2008 2086 Gangler

Miscellaneous

MSSQL sp_rename functionif exists(select * from sysobjects where name =

'SEQ_ECOMM2_CONTRACTTERM' and uid=user_id())

exec sp_rename 'SEQ_ECOMM2_CONTRACTTERM', 'SEQ_ECOMM2_CONTRACTTERM_SEQ';

exec sp_rename 'Publication.IsRegistered', 'IsDoiRegistered', 'COLUMN';

ORACLE sp_rename equivalent

no oracle “sp_rename” equivalent – must use PL/SQL, or alter table.

VIEWS

• MSSQL doesn’t have create or replace view – so they drop first than create

Page 47: 2008 2086 Gangler

CAST / Concatenation Diff

• Oracle

– UPDATE ad_data SET description = 'Ad '||

CAST(adId AS VARCHAR2(19)) WHERE description IS NULL;

• MSSQL

– UPDATE ad_data SET description = 'Ad ' + CAST(adId AS VARCHAR) WHERE description IS

NULL

Page 48: 2008 2086 Gangler

References

• Migrating Applications from Microsoft SQL

Server to Oracle 9i Database

– Oracle White Paper

– November 2003

• Microsoft SQL Server and Oracle Compared

– Download.oracle.com/docs/

• Microsoft SQLServer 2005 for the

experienced Oracle Database Administrator

– Microsoft Course 7033A

Page 49: 2008 2086 Gangler

Items Learned in this Session

• Basic differences between Oracle and MSSQL

– Database, Instance, Memory and Storage

Architecture

– Terminology

• Database locks

• Data Objects

• Data Types

• DML Examples

Page 50: 2008 2086 Gangler

Thank You for Attending

Thank you,

Questions?

[email protected]

Please fill out your evaluation form.

Migrating SQL Server 2005 Applications to Oracle

Mike Gangler

Paper # 2086