The DBMS_XA package provides the XA/Open interface for applications to call the XA interface in PL/SQL.
With this package, application developers can use PL/SQL to switch or share transactions between OceanBase Client sessions or processes.
The DBMS_XA subprograms allow PL/SQL applications to define global transaction branch IDs (XIDs) and associate or dissociate the current session with a transaction branch.
Applicability
This content applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
Privilege requirements
The DBMS_XA package is created under the SYS schema. The current invoker executes the operations provided by this package, not the package owner SYS. The DBMS_XA subprograms are executed in the context of the current user's privileges. When calling a PL/SQL anonymous block, the privileges of the stored procedure owner are used.
Users who need to execute the XA_RECOVER subprogram must have the SELECT or READ privilege on SYS.DBA_PENDING_TRANSACTIONS.
Considerations
The XA specification conforms to the X/Open CAE standard for distributed transaction processing. The XA_PREPARE, COMMIT, ROLLBACK, and FORGET subprograms may not be called while a transaction is still associated with the current session. These subprograms can only be called after the XA_END subprogram has been executed and no transaction is associated with the current session.
If a transaction is associated with the current session, the XA_PREPARE, COMMIT, ROLLBACK, and FORGET subprograms will return the XAER_PROTO error.
Before calling any subprogram in the DBMS_XA package, a connection or session must be established with the backend of OceanBase Database or the ResourceManager (ResourceManager identifiers are not supported). If multiple ResourceManagers are involved, multiple connections or sessions must be established for each ResourceManager before calling any subprogram in the DBMS_XA package. If multiple connections or sessions are established during global transaction processing, the caller must ensure that all connections or sessions associated with a specific global transaction branch ID (XID) are established with the same ResourceManager.
Overview of DBMS_XA subprograms
The following table lists the DBMS_XA subprograms supported in the current version of OceanBase Database and their brief descriptions.
| Subprogram | Description |
|---|---|
| DIST_TXN_SYNC | Synchronization recovery.
NoteOceanBase Database supports this procedure only for compatibility and does not perform any actual operations. |
| XA_COMMIT | Commits the global transaction specified by xid. |
| XA_END | Dissociates the current session from the transaction branch specified by xid. |
| XA_FORGET | Requests the ResourceManager (RM) to discard the transaction branch that has been committed or rolled back. |
| XA_GETLASTOER | Retrieves the last error code if a previous XA call failed. |
| XA_PREPARE | Prepares to commit the transaction branch specified by xid. |
| XA_RECOVER | Retrieves a list of prepared, committed, or rolled-back transaction branches (but transaction information has not been discarded) from the ResourceManager (RM). |
| XA_ROLLBACK | Requests the ResourceManager (RM) to roll back the transaction branch. |
| XA_SETTIMEOUT | Sets the transaction timeout interval (in seconds) for the current session. |
| XA_START | Associates the current session with the transaction branch specified by xid. |
