LWLock - buffer_content
buffer_content event occurs when a session is waiting to read or write a data page in memory while another session has that page locked for writing.
To read or manipulate data, PostgreSQL accesses it through shared memory buffers. To read from the buffer, a process gets a lightweight lock (LWLock) on the buffer content in shared mode. To write to the buffer, it gets that lock in exclusive mode. Shared locks allow other processes to concurrently acquire shared locks on that content. Exclusive locks prevent other processes from getting any type of lock on it.
buffer_content event indicates that multiple processes are attempting to get a lock on contents of a specific buffer.
buffer_content event appears more than normal, possibly indicating a performance problem, typical causes include the following:
Increased concurrent updates to the same data
There might be an increase in the number of concurrent sessions with queries that update the same buffer content. This contention can be more pronounced on tables with a lot of indexes.
Workload data is not in memory
When data that the active workload is processing is not in memory, these wait events can increase. This effect is because processes holding locks can keep them longer while they perform disk I/O operations.
Excessive use of foreign key constraints
Foreign key constraints can increase the amount of time a process holds onto a buffer content lock. This effect is because read operations require a shared buffer content lock on the referenced key while that key is being updated.
We recommend different actions depending on the causes of your wait event. You might identify
buffer_content events by querying the view
To increase the chance that active workload data is in memory, partition tables or scale up your instance class.
Investigate workloads experiencing high numbers of
buffer_content wait events for usage of foreign key constraints. Remove unnecessary foreign key constraints.
For workloads experiencing high numbers of
buffer_content wait events, identify unused indexes and remove them.