The isolation level associated with an application process defines the degree of isolation of that application process from other concurrently executing application processes. The isolation level of an application process, P, therefore specifies:
Isolation level is specified as an attribute of a package and applies to the application processes that use the package. The isolation level is specified in the program preparation process. Depending on the type of lock, this limits or prevents access to the data by concurrent application processes. The database manager supports three types of locks:
The following descriptions of isolation levels refer to locking data in row units. Logically, locking occurs at the base table row. The database manager, however, can escalate a lock to a higher level. An application process is guaranteed at least the minimum requested lock level.
The DB2 Universal Database database manager supports four isolation levels. Regardless of the isolation level, the database manager places exclusive locks on every row that is inserted, updated, or deleted. Thus, all isolation levels ensure that any row that is changed by this application process during a unit of work is not changed by any other application processes until the unit of work is complete. The isolation levels are:
Level RR ensures that:
RR does not allow phantom rows (see Read Stability) to be seen.
In addition to any exclusive locks, an application process running at level RR acquires at least share locks on all the rows it references. Furthermore, the locking is performed so that the application process is completely isolated (6) from the effects of concurrent application processes.
Like level RR, level RS ensures that:
Unlike RR, RS does not completely isolate the application process from the effects of concurrent application processes. At level RS, application processes that issue the same query more than once might see additional rows. These additional rows are called phantom rows.
For example, a phantom row can occur in the following situation:
In addition to any exclusive locks, an application process running at level RS acquires at least share locks on all the qualifying rows.
Like the RR level:
Unlike the RR level:
In addition to any exclusive locks, an application process running at level CS has at least a share lock for the current row of every cursor.
(5) The rows must be read in the same unit of work as the corresponding OPEN statement. See WITH HOLD in DECLARE CURSOR.
(6) Use of the optional WITH RELEASE clause on the CLOSE statement means that any guarantees against non-repeatable read and phantoms no longer apply to any previously accessed rows if the cursor is reopened.
(7) Use of the optional WITH RELEASE clause on the CLOSE statement means that any guarantees against non-repeatable read no longer apply to any previously accessed rows if the cursor is reopened.