Lock:Relation - Amazon Relational Database Service (original) (raw)

The Lock:Relation event occurs when a query is waiting to acquire a lock on a table or view (relation) that's currently locked by another transaction.

Topics

Supported engine versions

This wait event information is supported for all versions of RDS for PostgreSQL.

Context

Most PostgreSQL commands implicitly use locks to control concurrent access to data in tables. You can also use these locks explicitly in your application code with the LOCK command. Many lock modes aren't compatible with each other, and they can block transactions when they're trying to access the same object. When this happens, RDS for PostgreSQL generates a Lock:Relation event. Some common examples are the following:

For more information about table-level locks and conflicting lock modes, seeExplicit Locking in the PostgreSQL documentation.

Blocking queries and transactions typically unblock in one of the following ways:

Likely causes of increased waits

When the Lock:Relation event occurs more frequently than normal, it can indicate a performance issue. Typical causes include the following:

Increased concurrent sessions with conflicting table locks

There might be an increase in the number of concurrent sessions with queries that lock the same table with conflicting locking modes.

Maintenance operations

Health maintenance operations such as VACUUM andANALYZE can significantly increase the number of conflicting locks. VACUUM FULL acquires an ACCESS EXCLUSIVE lock, and ANALYSE acquires a SHARE UPDATE EXCLUSIVE lock. Both types of locks can cause aLock:Relation wait event. Application data maintenance operations such as refreshing a materialized view can also increase blocked queries and transactions.

Locks on reader instances

There might be a conflict between the relation locks held by the writer and readers. Currently, only ACCESS EXCLUSIVE relation locks are replicated to reader instances. However, the ACCESS EXCLUSIVE relation lock will conflict with any ACCESS SHARE relation locks held by the reader. This can cause an increase in lock relation wait events on the reader.

Actions

We recommend different actions depending on the causes of your wait event.

Topics

Reduce the impact of blocking SQL statements

To reduce the impact of blocking SQL statements, modify your application code where possible. Following are two common techniques for reducing blocks:

Minimize the effect of maintenance operations

Maintenance operations such as VACUUM andANALYZE are important. We recommend that you don't turn them off because you find Lock:Relation wait events related to these maintenance operations. The following approaches can minimize the effect of these operations: