Entering content frame

Function documentation Locks Locate the document in its SAP Library structure

Use

In principle, several transactions can access the same database object, such as a table, at the same time. The database system uses locks to synchronize the parallel processes and isolate individual transactions from each other.

Types of locks

Name

Objects that can be locked

Shared lock (SHARE LOCK)

Tables, rows, database catalog

Exclusive lock (EXCLUSIVE LOCK)

Tables, rows, database catalog

Optimistic Lock

Rows

Activities

Requesting Locks

Locks for rows or tables can be requested/released implicitly by the database system, or explicitly requested/released by a user (see the Reference Manual, LOCK Statement). Locks for the database catalog are always requested and released implicitly by the database system.

·        You use the isolation level to determine when which type of lock is set and to determine the degree of parallelism of transactions and the phenomena that can occur. You can specify the isolation level when you start a database session. If you do not specify an isolation level, the database system uses the default value.

Depending on the isolation level, the database system then requests the necessary locks as the SQL statements are being processed. SQL statements that change data (such as INSERT, UPDATE, DELETE) always request an exclusive lock.

·        With a LOCK statement you can request explicit locks for a transaction or lock individual rows in a table by specifying a LOCK option within an SQL statement. This is possible in every isolation level. You can use the LOCK option to temporarily override the isolation level for some SQL statements.

If too many row locks are requested in a table by a transaction, then the database system tries to set a table lock on it. You configure the limit from which the database system tries to turn row locks into a table lock using the MAXLOCKS general database parameter.

Releasing Locks

Type of Lock

Release

Requested explicitly by the user with the LOCK statement

The database system releases the lock after the end of the transaction. Exception: the COMMIT statement or the ROLLBACK statement that ends the transaction also contains a LOCK statement.

Implicitly set shared lock

Depends on the isolation level

Implicitly set exclusive lock

Exclusive lock for changed rows

Exclusive locks that were requested by a SQL statement that changed data

Table locks

Not released within a transaction, but after the end of the whole transaction instead

Exclusive lock for rows that have not yet changed

Shared lock for rows

Can be released by an UNLOCK statement

Use the REQUEST_TIMEOUT special database parameter to restrict the time that users wait for a lock to be released. When this time runs out, there is a database system message and you can react to it by terminating the transaction, for example. In such situations, the database system does not perform an implicit ROLLBACK.

Displaying Lock Information

You can display information about the locks that are set as follows:

·        The LOCKS system table contains information about locks; LOCK_WAITS contains information about the lock requests.

·        Database Manager GUI, Displaying Database Activities

·        In SAP systems, use the Structure linkDatabase Assistent to display database information, or the Structure linkliveCache Assistant for liveCache instances.

 

Leaving content frame