Wednesday, October 15, 2025

Oracle Saga Framework

Do you know about Oracle Saga Framework ? #JoelKallmanDay


Saga oracle refers to the Oracle database framework for implementing the Saga pattern, which manages data integrity across distributed microservices by breaking long-running business transactions into a sequence of local transactions. If a step fails, it uses compensating transactions to automatically roll back the changes in the preceding steps. 


This eliminates the need for traditional distributed locks and is integrated into the Oracle database with features like PL/SQL packages, Advanced Queuing (AQ) integration, and lock-free reservations.  


Key features 

  • Database-centric approach: The framework is built directly into the Oracle database, making it a natural fit for data-driven microservices. 
  • Compensation-aware: It automatically handles rollbacks when a saga fails by executing compensating transactions for the services that have already completed. 
  • Leverages database features: It utilizes Oracle's Advanced Queuing (AQ) for messaging and offers lock-free reservations for improved transactional concurrency, which automatically invokes compensating transactions on rollback. 
  • Integration: It integrates with other Oracle technologies like transaction event queues and provides specialized annotations for Java applications, aligning with standards like Eclipse MicroProfile
  • Administrative and client interfaces: It provides interfaces for administrators to manage sagas and for applications to initiate, participate in, and complete them. 

How it works 

Each step in a saga is a local transaction within a single microservice. The framework coordinates these local transactions, ensuring that they either all succeed or are undone in reverse order if any one of them fails. For example, in a travel booking saga: 


  1. Step 1: A local transaction in the "flight" service books a flight and publishes an event to the next service. 
  2. Step 2: The "hotel" service receives the event, books a hotel via its own local transaction, and publishes an event to the next service. 
  3. Step 3: If a "car" service fails to book a car, the framework will trigger a compensating transaction in the "hotel" service to cancel the hotel reservation, and then a compensating transaction in the "flight" service to cancel the flight reservation. 

Developing Applications with Sagas

This chapter covers Saga APIs that allow applications that are built using microservices principles to incorporate efficient transactions across microservices. 

Saga APIs are implemented while closely following the Long Running Action (LRA) specification from Eclipse MicroProfile.


Implementing Sagas with Oracle Database

You can use Oracle Database as a platform to build your Saga-based, on-cloud or on-premises applications. When you implement Sagas with Oracle Database for handling distributed transactions, you can leverage the robust underlying infrastructure built into Oracle Database. 


The Saga infrastructure maintains the global application state for microservices, facilitating development and throughput.

The following are some key benefits of using Oracle Database for Saga implementation:


  • The Saga implementation is integrated in the database to make Sagas simpler to code, deploy, and maintain.
  • Simplified Saga annotations following the Eclipse LRA standard make it easy to enable transactions across microservices using Oracle Database.
  • Data consistency is achievable across microservices.
  • Auto-compensating logic based on lock-free, reservable columns is provided in the database to handle rollbacks on Saga rollback.
  • Advanced Queuing (AQ) and Oracle Transactional Event Queues (TxEventQ) messaging platforms are built into Oracle Database, enabling microservices to produce and consume messages and events as part of database transactions.
  • Support is provided for different languages, including PL/SQL and Java applications.
  • The Saga framework recommends a JSON type for representing the application payload.
  • There is improved availability and scalability for applications that require transactions across microservices. Such transactions are common with monolith applications that are converting to microservices, where transactions may span multiple bounded contexts. Note that a bounded context is an explicit boundary within which a business domain model exists.


Oracle Saga Framework Overview

The Oracle Saga framework provides the foundation to implement and administer Sagas for microservices applications built using Oracle Database. 

The framework provides administrative and client interfaces. Administrative interfaces enable Saga applications to configure and manage Saga participants and message brokers. 


Client interfaces enable applications to initiate, participate, and finalize Sagas. 

Saga participants are automatically configured with message channels and message propagation. 

The Saga framework is compensation-aware and provides for automatic rollback of the affected data when a Saga is rolled back. 

The Saga framework includes PL/SQL packages, dictionary tables, and Advanced Queuing (AQ) integration that facilitate Sagas in the database.

The Oracle Saga framework leverages two important features of Oracle Database. 

There is a transaction layer with reservable column support that enables recording of appropriate meta-information when reservable columns are updated.

The reservable column support invokes compensating transactions automatically to revert the state of the reservable column updates when a Saga is rolled back. 

Reservable columns are a part of the lock-free reservation feature that Oracle provides to improve transactional concurrency.

Another important layer integrated into the database is the event queues built on the Oracle Advanced Queuing (AQ) technology. 


AQ provides the asynchronous messaging platform that connects various microservice participants. The Saga framework deploys a hub-and-spoke topology to connect Saga initiators, coordinators, and participants. The Saga message broker acts as the hub in this topology.


Saga Framework Features

The Saga framework provides the following features for implementing Sagas on Oracle Database:

  • PL/SQL administrative interfaces to add and manage active Sagas and Saga participants
  • PL/SQL and Java interfaces for applications to interact with the Saga framework, and participate and finalize (commit or rollback) database Sagas
  • Asynchronous message communication across multiple participants that contribute to a Saga, facilitated by microservice-specific AQ message propagation infrastructure from Oracle
  • Reservable column-based Saga finalization (compensation and completion) support to enable recording of reservable column updates, and auto-compensation of transactions to roll back changes for canceled Sagas
  • User-defined Saga finalization (compensation and completion) support to enable users to explicitly define and automatically execute Saga finalization
  • Strong messaging semantics to ensure that interservice messages are delivered exactly once and never lost or duplicated
  • Saga ID support to bind individual transactions to the Saga ID
  • A globally unique name for each participant in a Saga
  • Automatic configuration of message channels and message propagation for Saga participants that are provisioned into the system
  • Various dictionary tables to maintain the status of Sagas
  • System-defined views to report on Sagas and Saga participants in the system
  • Eclipse Microprofile LRA specification emulation


Saga Framework Concepts


Saga Participant and Initiator

A Saga participant represents a spoke (participant microservice) in the Saga topology that either initiates and orchestrates a Saga or enrolls to participate in one. A participant is associated with a message broker (that is local or remote) and optionally with a local Saga coordinator. Saga participants that initiate Sagas are described in this document as "initiators" and non-initiator participants are described as "participants". Saga initiators must be associated with a Saga coordinator. In the initial version, the Saga framework only supports a local Saga coordinator (from the same PDB) for an initiator. Meanwhile, a Saga participant need not be associated with a coordinator and can be remote to the initiator.

Any participant can initiate a Saga. A Saga initiator is a microservice that initiates a Saga and enrolls other microservice participants by sending asynchronous messages.

In the travel agency example that follows, the participant microservices are the flight service, hotel service, and car service. A participant microservice executes one or more participant transactions on behalf of a Saga. Compensation action for a participant transaction is maintained in the local PDB. Participants are responsible for maintaining the local state of their Sagas.


Transaction Coordinator

A transaction coordinator acts as a transaction manager in the Saga topology. The Saga coordinator maintains the Saga state on behalf of the Saga initiator.

A Saga topology can have several Saga coordinators. In the initial release of the Saga framework, a Saga participant can only associate with coordinators who are local (same PDB and schema) to the participants. A coordinator can, however, associate with a local or remote message broker.


Message Broker

A message broker acts as an intermediary and represents the hub in the Saga topology. A broker provides a message delivery service for the message propagation between two or more Saga participants and their coordinator. Each Saga participant or coordinator is associated with a single broker, who can be local or remote. A broker does not maintain any Saga state.


Hope this topic helps you.

Friday, October 10, 2025

Read-Only Oracle Home in 23ai

 About Read-Only Oracle Homes 


            Alireza Kamrani 

              


Read-Only Oracle Homes (ROOH) were introduced in Oracle Database 18c and have become the recommended default structure for newer Oracle installations. The idea is to separate static, immutable binaries from instance-specific and writable files — making database software more secure, easier to manage, and simpler to patch or clone.


In 23ai:

With Oracle Database 23ai, an Oracle home is available in read/write mode by default. However, you can choose to configure an Oracle home in read-only mode after you have performed a software-only Oracle Database installation.

A read-only Oracle home does not imply that the file system and the Oracle home is in read-only mode. The file system and mount point should always be in read/write mode.

A read-only Oracle Home simplifies provisioning by implementing separation of installation and configuration.

In a read-only Oracle home, the configuration data and log files reside outside of the read-only Oracle home. 


Apart from the traditional ORACLE_BASE andORACLE_HOME directories, the following directories contain files that used to be in ORACLE_HOME:

Ensure that you enable read-only Oracle home before you create the database or listener.

When you run the roohctl script to enable a read-only Oracle home, the Oracle home file system will continue to be a read/write file system.


Note:

This feature does not affect how database administrators monitor, diagnose, and tune their system performance.


Key Benefits:

1. Simplified Patching

•Patch once → apply everywhere.

Since the binaries are immutable, you can:

•Maintain one gold (reference) home image.

•Deploy or patch by replacing the home instead of in-place patching.

•This makes rolling patchingcloning, and rollback operations much faster and safer.


2. Improved Security

•The home being read-only means:

•No accidental or malicious changes to Oracle binaries.

•Reduces attack surface since configuration and logs are stored elsewhere.

•Protects integrity of Oracle software from OS-level tampering.


3. Simplified Administration

•No need to separate writable and read-only files manually.

•Easier configuration management — all instance-specific writable files (e.g., listener config, tnsnames, sqlnet.ora) are automatically redirected to the appropriate directory under $ORACLE_BASE_HOME.

•Supports multiple databases or instances sharing a single home safely.


4. Faster Deployment and Cloning

•You can clone a read-only home simply by copying it to another server — no need to reconfigure.

•When you deploy, only instance-specific config is customized in $ORACLE_BASE_HOME.

•Great for cloud or fleet-managed environments.


5. Reduced Storage and Maintenance Overhead

•Shared read-only binaries across databases minimize duplication.

•Less storage needed for multiple homes.

•Easier to keep environments consistent (no “drift” between installations).


6. Better Compliance and Auditing

•Software binaries are immutable — simplifying validation for compliance (e.g., SOX, ISO, PCI).

•Changes to configuration are centralized and easier to track.


About Oracle Base Config

Both, in a read-only ORACLE_HOME and read/write ORACLE_HOME, the configuration files reside in a location known as ORACLE_BASE_CONFIG.


In a read/write ORACLE_HOME, the ORACLE_BASE_CONFIG path is the same as the ORACLE_HOME path because it is located at $ORACLE_HOME. However, in a read-only ORACLE_HOME, the ORACLE_BASE_CONFIG path is the same as ORACLE_BASE.


ORACLE_BASE_CONFIG/dbs contains the configuration files for ORACLE_HOME. Each file in the dbs directory contains $ORACLE_SID so that the directory can be shared by many different ORACLE_SIDs.


To print the ORACLE_BASE_CONFIG path, run the orabaseconfig command from the $ORACLE_HOME/bin directory:


$ setenv ORACLE_HOME /u01/app/oracle/product/23.0.0/dbhome_1

$ cd $ORACLE_HOME/bin

$ ./orabaseconfig


The orabaseconfig command returns the location of ORACLE_BASE_CONFIG irrespective of whether the home is a read-only ORACLE_HOME or a read/write ORACLE_HOME. 


For example, to know the location of configuration files like SPFILE and the password file, run orabaseconfig:


Example: Output in Read-Only ORACLE_HOME


$ ./orabaseconfig

/u01/app/oracle


Where, /u01/app/oracle is the ORACLE_BASE.

Example 12-4 Output in Read/Write ORACLE_HOME


$ ./orabaseconfig

/u01/app/oracle/product/23.0.0/dbhome_1


where, /u01/app/oracle/product/23.0.0/dbhome_1is the ORACLE_HOME.


Enabling a Read-Only Oracle Home

Configure your Oracle home as a read-only Oracle home after you have performed a software-only Oracle Database installation.

To enable a read-only Oracle home:

  1. Perform a software-only Oracle Database installation.
  2. Run the roohctl -enable script.
  3. Run Oracle Database Configuration Assistant (Oracle DBCA) to create a database.


Note:

Ensure that you enable read-only Oracle home before you create the database or listener.


Software-Only Database Installation

  1. Log in as the Oracle installation owner user account (oracle) that you want to own the software binaries.
  2. Download the Oracle Database installation image files (db_home.zip) to a directory of your choice. For example, you can download the image files to the /tmp directory.
  3. Create the Oracle home directory and extract the image files that you have downloaded in to this Oracle home directory. For example:

    $ mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
  4. $ chown oracle:oinstall /u01/app/oracle/product/19.0.0/dbhome_1
  5. $ cd /u01/app/oracle/product/19.0.0/dbhome_1
  6. $ unzip -q /tmp/db_home.zip


    Note
    Ensure that the Oracle home directory path you create is in compliance with the Oracle Optimal Flexible Architecture recommendations. Also, unzip the installation image files only in this Oracle home directory that you created.
  7. From the Oracle home directory, run the runInstaller command to start the Oracle Database installer. 
  8. In the Select Configuration Option screen, select Set Up Software Only.
  9. Select your installation type. Installation screens vary depending on the installation option you select. Respond to the configuration prompts as needed.


Run the roohctl Script

  1. Go to the bin directory

    $ cd /u01/app/oracle/product/19.0.0/dbhome_1/bin
  2. Run the roohctl script to enable read-only Oracle home.

    $ ./roohctl -enable 
  3. On Oracle Real Application Clusters (Oracle RAC) installations, run the preceding roohctl script on every node of the cluster. Alternatively, run the roohctl script with the nodelistoption and provide the list of cluster nodes:

    $ ./roohctl –enable –nodelist 
    comma_separated_list_of_nodes

Copying demo Directories to Oracle Base Home

In a read-only mode ORACLE_HOME, you must copy the demo directories listed in this topic from ORACLE_HOME to ORACLE_BASE_HOME.

Oracle Database contains various demo directories that include a variety of examples and product demonstrations that you can use to learn about the products, options, and features of Oracle Database. In a read-only mode ORACLE_HOME, you cannot use these demo directories in ORACLE_HOME because writes are performed to these demodirectories when they are used.


Many of the demo directories are not available by default. You must install Oracle Database Examples to view and use the examples and product demonstrations.

Copy the respective demo directory to the corresponding location in ORACLE_BASE_HOME. Now, you can use this copy of the demo directory.


You must copy the following demo directories from ORACLE_HOME to ORACLE_BASE_HOME:

You must also create symbolic links for the odbc/demo, precomp/demo, rdbms/demo, and xdk/demo demo directories. See the "Creating Symbolic Links" section in this topic.


Copying demo Directories

For example, to copy the rdbms/demo directory from ORACLE_HOME to ORACLE_BASE_HOME, perform the following:


  1. Login as the Oracle software owner user (oracle).
  2. Check if the rdbms/demo directory is copied to ORACLE_BASE_HOME.

    $ ls -l -d $(orabasehome)/rdbms/demo
  3. If the rdbms/demo directory has not been copied, then create it and copy it.

    $ mkdir -p $(orabasehome)/rdbms
  4. $ cp -r $ORACLE_HOME/rdbms/demo $(orabasehome)/rdbms/demo

Similarly, copy all the demo directories listed earlier from ORACLE_HOME to ORACLE_BASE_HOME.


Creating Symbolic Links

You must create symbolic links for the odbc/demo, precomp/demo, rdbms/demo, and xdk/demo demodirectories.

For rdbms/demo, replace $ORACLE_HOME/rdbms/demo with a symbolic link to the copy.

  1. Ensure that the symbolic link does not already exist.

    $ ls -l -d $ORACLE_HOME/rdbms/demo
  2. If $ORACLE_HOME/rdbms/demo is still the original demo directory, rename it and replace it with the symbolic link.

    $ cd $ORACLE_HOME/rdbms
  3. $ mv demo demo.installed
  4. $ ln -s $(orabasehome)/rdbms/demo $ORACLE_HOME/rdbms/demo

For odbc/demo, replace $ORACLE_HOME/odbc/demo with a symbolic link to the copy.

  1. Ensure that the symbolic link does not already exist.

    $ ls -l -d $ORACLE_HOME/odbc/demo
  2. If $ORACLE_HOME/odbc/demo is still the original demo directory, rename it and replace it with the symbolic link.

    $ cd $ORACLE_HOME/odbc
  3. $ mv demo demo.installed
  4. $ ln -s $(orabasehome)/odbc/demo $ORACLE_HOME/odbc/demo

For precomp/demo, replace $ORACLE_HOME/precomp/demo with a symbolic link to the copy.

  1. Ensure that the symbolic link does not already exist.

    $ ls -l -d $ORACLE_HOME/precomp/demo
  2. If $ORACLE_HOME/precomp/demo is still the original demo directory, rename it and replace it with the symbolic link.

    $ cd $ORACLE_HOME/precomp
  3. $ mv demo demo.installed
  4. $ ln -s $(orabasehome)/precomp/demo $ORACLE_HOME/precomp/demo

The xdk/demo directory requires a symbolic link at $ORACLE_HOME/xdk/include pointing to $(orabasehome)/xdk/include after you copy the xdk/demo directory.

  1. Ensure that the symbolic link does not already exist:
    $ ls -l -d $ORACLE_HOME/xdk/include
  2. If the symbolic link does not exist, then, run the following command:

    $ ln -s $ORACLE_HOME/xdk/include $(orabasehome)/xdk/include

Note:

In the plsql/demo directory, ncmpdemo.sqlis unusable in read-only mode.


Copying the init.ora File

Copy the init.ora file from ORACLE_HOME to ORACLE_BASE_HOME.

  1. Login as the Oracle software owner user (oracle).
  2. Check if the init.ora file exists in ORACLE_BASE_HOME.

    $ ls $(orabasehome)/init.ora 

    If an init.ora file exists in ORACLE_BASE_HOME, then update this init.ora file to be in-sync with the$ORACLE_HOME/init.ora file.
  3. If the init.ora file does not exist in ORACLE_BASE_HOME, then copy it from ORACLE_HOME.

    $ cp $ORACLE_HOME/init.ora $(orabasehome)/init.ora





Oracle Saga Framework

Do you know about Oracle Saga Framework ?  #JoelKallmanDay Saga   oracle  refers to the Oracle database framework for implementing the Saga ...