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:
The 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. For details on different types and attributes of specific locks refer to the Administration Guide. Declared temporary tables and the rows of declared temporary tables are not locked at all because they are only accessible by the application that declared the temporary tables. Thus, the following discussion on locking and isolation levels does not apply to declared temporary tables.
The database manager supports three general categories of locks:
accessing the data in any way except for application processes with an isolation level of uncommitted read, which can read but not modify the data. (See Uncommitted Read (UR).)
Locking occurs at the base table row. The database manager, however, can replace multiple row locks with a single table lock. This is called lock escalation. 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 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.
For a SELECT INTO, FETCH with a read-only cursor, fullselect used in an INSERT, row fullselect in an UPDATE, or scalar fullselect (wherever used), level UR allows:
For other operations, the rules of level CS apply.
A comparison of the four isolation levels can be found on Appendix I, Comparison of Isolation Levels.