Monitoring Row Locks
For general query logging from errors, try setting the log_min_error_statement[285] parameter. This logs queries to the postgresql.log file when they’re blocked. Another more targeted option is the log_lock_waits parameter, which you’ll see in an upcoming section.
One gotcha to be aware of is mentioned in the post “Selecting for Share and Update in PostgreSQL.”[286] When using SELECT...FOR UPDATE, referenced tables from foreign key columns will also be locked from SELECT...FOR UPDATE. This behavior is necessary to maintain referential integrity.
When that’s too onerous, a weaker type of lock is SELECT...FOR SHARE. This lock type creates a shared lock on the rows being selected. A shared lock allows concurrent reads for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access