OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida [email protected].

33
OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben @ openforce .net

Transcript of OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida [email protected].

Page 3: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Context

• Building a multi-user,networked application

• Open-Source hackers have ignored the RDBMS for too long!

• The Next Open-Source ChallengeCan PostgreSQL replace Oracle?

Page 4: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Outline

• Open-Source and RDBMSs• Oracle & PostgreSQL comparison

– SQL support– Maintenance– Advanced Features

• Building a DB-independent App• OpenACS

Page 5: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Data in Networked Apps

• Multiple users accessing data– Read & Write– Contention!

• Multiple means of access– Web server– Command line– Automated batch scripts

Page 6: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Data Abstraction

• Assurances made to application• Understanding Failure:

– Sometimes, you must fail– If you fail, admit it and fail gracefully

• Understanding Relevancy:– Sometimes certain data is irrelevant

Page 7: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

ACID

Abstraction for reliable data storage:

• Atomicity• Consistency• Isolation• Durability

Page 8: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Atomicity

• All or nothing• Much more than locking!

Page 9: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Consistency

• Invariants - Consistent States• Complex Data Invariants

– Audit Tables– Aggregate Checks

• Logic in the DB• Logic triggered within

transactional control

Page 10: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Isolation

• Partial work invisible to others• Levels of Isolation

– Dirty Reads– Read Committed– Read Repeatable– Serializable

Page 11: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Durability

• Once committed, a transaction is permanent -- no more rollbacks!

• Point-In-Time Recovery• Impact on Backups

Page 12: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

ACID in the DB

• locking, rollback in the application layer? Abstraction!

• Guarantees must be made no matter how data is accessed

• Isolation mandates implementation at low-level

Page 13: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

ACID is not Enough!

• Naïve Implementation– single-threaded– global lock– full write to disk before commit.

• Get Fired• Optimistic behavior

Page 14: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Does this Work?

begin transaction;

v_balance:= select balance from accounts where account_id=1;

update accounts set balance= v_balance+20 where account_id=1;

commit transaction;

Page 15: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

This Does!

begin transaction;

v_balance:= select balance from accounts where account_id=1 for update;

update accounts set balance= v_balance+20 where account_id=1;

commit transaction;

Page 16: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Oracle - an Overview

• ACID-compliant• Highly optimized for OLTP• Highly configurable• Very complex administration• OPS: the Promised Land

Page 17: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

PostgreSQL - an Overview

• ACId-compliant• Highly optimized for OLTP• Not so configurable• Very simple administration• Replication in the works

Page 18: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

SQL support

• SQL92 - the “standard”• No specifications for stored

procedures or triggers!• Ambiguities• Oracle’isms

– Connect By– Dates– SQL92 alternatives

Page 19: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

SQL support

• Aggregates• Joins, outer joins• Subselects• Views• On-the-fly views

Page 20: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Stored Procedures

Oracle• PL/SQL, Java

• Triggers (statement and rowlevel)

PostgreSQL• PL/pgSQL, PL/Perl,

PL/Tcl, PL/C• Triggers

(rowlevel only)

Page 21: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Transaction Engine

Oracle• Overwrite• Rollback Segment• Transaction Log

(Redo Log)• Row-Level

Locking• Optimistic

PostgreSQL• No-overwrite• Versioning• Transaction Log

(as of v7.1)• Row-Level

Locking• Optimistic

Page 22: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Backup & Recovery

Oracle• Logical Dump (not

consistent!)• Incremental

dumps using physical backup

• Point-in-time recovery

PostgreSQL• Logical Dump

(consistent)• No incremental

dumps• No point-in-time

recovery yet

Page 23: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Oracle Architecture

Tablespace

Rollback Segments

Page 24: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

PostgreSQL Architecture

……

Field: price

Val: 120

Version #

1659

Field: price

Val: 110

Version #

1660

Field: name

Val: “Tim”

Version #

1660

Field: price

Val: 120

Version #

1661

Page 25: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Parallelism

Oracle• OPS• Very few users• However, a huge

advantage in large installations

PostgreSQL• Asynchronous

replication• Synchronous in

the works• No complete

solution yet

Page 26: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

SQL Applications

• Interface via ODBC/JDBC, DBI, etc..• SQL statements

– Many static, w/ bind variablesSelect * from users where user_id = :user_id

– Some dynamicSelect * from users where $date_predicate

Page 27: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

Summary

• PostgreSQL can do 90% of what Oracle can do

• You probably need 70% of what Oracle can do

• PostgreSQL is ready for many enterprise systems.

Page 28: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

OpenACS - History

• 1995 - AOLserver/Tcl/Illustra• 1997 - AOLserver/Tcl/Oracle• 1999 - AOLserver/Tcl/PostgreSQL• 2001 - v4.x, multi-DB capable,

modular

Page 29: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

OpenACS 4.x Architecture

• PostgreSQL data model and stored procedures

• Queries stored in XML• Templates• AOLserver/Tcl logic

Page 30: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

OpenACS Stack

O/S

RDBMS

App Server

Presentation

Op

en

AC

S

Cust

om

Code

All Free Software

Page 31: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

OpenACS 4.x Features

• A common user table - collaboration• Registration/Login/Permissions• Discussion Forums• Ecommerce• Calendaring• Education! (MIT Sloan)

Page 32: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

OpenACS 4.x Demo

Page 33: OpenACS: Porting Oracle Applications to PostgreSQL Ben Adida ben@openforce.net.

References

• http://postgresql.org• http://openacs.org• http://openacs.org/doc/openacs/??