The DB2® UDB for iSeries™ commitment control support provides a means to process a group of database changes like update, insert, DDL, or delete operations as a single unit of work (transaction).
A commit operation guarantees that the group of operations is completed. A rollback operation guarantees that the group of operations is backed out. A savepoint can be used to break a transaction into smaller units that can be rolled back. A commit operation can be issued through several different interfaces. For example,
A rollback operation can be issued through several different interfaces. For example,
The only SQL statements that cannot be committed or rolled back are:
If commitment control was not already started when either an SQL statement is executed with an isolation level other than COMMIT(*NONE) or a RELEASE statement is executed, then DB2 UDB for iSeries sets up the commitment control environment by implicitly calling the CL command Start Commitment Control (STRCMTCTL). DB2 UDB for iSeries specifies NFYOBJ(*NONE) and CMTSCOPE(*ACTGRP) parameters along with LCKLVL on the STRCMTCTL command. The LCKLVL specified is the lock level on the COMMIT parameter on the CRTSQLxxx, STRSQL, or RUNSQLSTM commands. In REXX, the LCKLVL specified is the lock level on the SET OPTION statement. You may use the STRCMTCTL command to specify a different CMTSCOPE, NFYOBJ, or LCKLVL. If you specify CMTSCOPE(*JOB) to start the job level commitment definition, DB2 UDB for iSeries uses the job level commitment definition for programs in that activation group.
For cursors where either COMMIT(*ALL), COMMIT(*RR), or COMMIT(*CS) with the KEEP LOCKS clause is specified and either catalog files are used or a temporary result table is required, DB2 UDB for iSeries will lock all referenced tables in shared mode (*SHRNUP). This will prevent concurrent processes from executing anything but read-only operations on the table(s). A message (either SQL7902 or CPI430A) is sent that says COMMIT(*ALL) is requested but not allowed. Message SQL0595 may also be sent.
If ALWBLK(*ALLREAD) and COMMIT(*CHG) were specified, when the program was precompiled, all read-only cursors will allow blocking of rows and a ROLLBACK HOLD will not roll the cursor position back.
If COMMIT(*RR) is requested, the tables will be locked until the query is closed. If the cursor is read-only, the table will be locked (*SHRNUP). If the cursor is in update mode, the table will be locked (*EXCLRD). Since other users will be locked out of the table, running with repeatable read will prevent concurrent access of the table.
If an isolation level other then COMMIT(*NONE) was specified and the application issues a ROLLBACK or the activation group ends abnormally (and the commitment definition is not *JOB), all updates, inserts, deletes, and DDL operations made within the unit of work are backed out. If the application issues a COMMIT or the activation group ends normally, all updates, inserts, deletes, and DDL operations made within the unit of work are committed.
DB2 UDB for iSeries uses locks on rows to keep other jobs from accessing changed data before a unit of work completes. If COMMIT(*ALL) is specified, read locks on rows fetched are also used to prevent other jobs from changing data that was read before a unit of work completes. This will not prevent other jobs from reading the unchanged rows. This ensures that, if the same unit of work rereads a row, it gets the same result. Read locks do not prevent other jobs from fetching the same rows.
Commitment control handles up to 500 million distinct row changes in a unit of work. If COMMIT(*ALL) or COMMIT(*RR) is specified, all rows read are also included in the limit. (If a row is changed or read more than once in a unit of work, it is only counted once toward the limit.) Holding a large number of locks adversely affects system performance and does not allow concurrent users to access rows locked in the unit of work until the end of the unit of work. It is in your best interest to keep the number of rows processed in a unit of work small.
Commitment control will allow up to 512 files for each journal to be open under commitment control or closed with pending changes in a unit of work.
COMMIT HOLD and ROLLBACK HOLD allows you to keep the cursor open and start another unit of work without issuing an OPEN again. The HOLD value is not available when you are connected to a remote database that is not on an iSeries system. However, the WITH HOLD option on DECLARE CURSOR may be used to keep the cursor open after a COMMIT. This type of cursor is supported when you are connected to a remote database that is not on an iSeries system. Such a cursor is closed on a rollback.
SQL statement | COMMIT parameter (see note 5) | Duration of row locks | Lock type |
---|---|---|---|
SELECT INTO |
*NONE |
No locks |
|
FETCH (read-only cursor) | *NONE |
No locks |
|
FETCH (update or delete capable cursor) (See note 1) | *NONE |
When row not updated or deleted |
UPDATE |
INSERT (target table) | *NONE |
No locks |
|
INSERT (tables in subselect) | *NONE |
No locks |
|
UPDATE (non-cursor) | *NONE |
Each row locked while being updated |
UPDATE |
DELETE (non-cursor) | *NONE |
Each row locked while being deleted |
UPDATE |
UPDATE (with cursor) | *NONE |
Lock released when row updated |
UPDATE |
DELETE (with cursor) | *NONE |
Lock released when row deleted |
UPDATE |
Subqueries (update or delete capable cursor or UPDATE or DELETE non-cursor) | *NONE |
From read until next FETCH |
READ |
Subqueries (read-only cursor or SELECT INTO) | *NONE |
No locks |
|
Notes:
|