Post on 31-Dec-2015
OpenACS:Porting Oracle Applications
to PostgreSQL
Ben Adidaben@openforce.net
Using an Enterprise-Ready Open-Source RDBMS
Ben Adidaben@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?
Outline
• Open-Source and RDBMSs• Oracle & PostgreSQL comparison
– SQL support– Maintenance– Advanced Features
• Building a DB-independent App• OpenACS
Data in Networked Apps
• Multiple users accessing data– Read & Write– Contention!
• Multiple means of access– Web server– Command line– Automated batch scripts
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
ACID
Abstraction for reliable data storage:
• Atomicity• Consistency• Isolation• Durability
Atomicity
• All or nothing• Much more than locking!
Consistency
• Invariants - Consistent States• Complex Data Invariants
– Audit Tables– Aggregate Checks
• Logic in the DB• Logic triggered within
transactional control
Isolation
• Partial work invisible to others• Levels of Isolation
– Dirty Reads– Read Committed– Read Repeatable– Serializable
Durability
• Once committed, a transaction is permanent -- no more rollbacks!
• Point-In-Time Recovery• Impact on Backups
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
ACID is not Enough!
• Naïve Implementation– single-threaded– global lock– full write to disk before commit.
• Get Fired• Optimistic behavior
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;
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;
Oracle - an Overview
• ACID-compliant• Highly optimized for OLTP• Highly configurable• Very complex administration• OPS: the Promised Land
PostgreSQL - an Overview
• ACId-compliant• Highly optimized for OLTP• Not so configurable• Very simple administration• Replication in the works
SQL support
• SQL92 - the “standard”• No specifications for stored
procedures or triggers!• Ambiguities• Oracle’isms
– Connect By– Dates– SQL92 alternatives
SQL support
• Aggregates• Joins, outer joins• Subselects• Views• On-the-fly views
Stored Procedures
Oracle• PL/SQL, Java
• Triggers (statement and rowlevel)
PostgreSQL• PL/pgSQL, PL/Perl,
PL/Tcl, PL/C• Triggers
(rowlevel only)
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
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
Oracle Architecture
Tablespace
Rollback Segments
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
Parallelism
Oracle• OPS• Very few users• However, a huge
advantage in large installations
PostgreSQL• Asynchronous
replication• Synchronous in
the works• No complete
solution yet
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
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.
OpenACS - History
• 1995 - AOLserver/Tcl/Illustra• 1997 - AOLserver/Tcl/Oracle• 1999 - AOLserver/Tcl/PostgreSQL• 2001 - v4.x, multi-DB capable,
modular
OpenACS 4.x Architecture
• PostgreSQL data model and stored procedures
• Queries stored in XML• Templates• AOLserver/Tcl logic
OpenACS Stack
O/S
RDBMS
App Server
Presentation
Op
en
AC
S
Cust
om
Code
All Free Software
OpenACS 4.x Features
• A common user table - collaboration• Registration/Login/Permissions• Discussion Forums• Ecommerce• Calendaring• Education! (MIT Sloan)
OpenACS 4.x Demo
References
• http://postgresql.org• http://openacs.org• http://openacs.org/doc/openacs/??