Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 176905

A mechanism for managing concurrent access to shared data or resources by granting temporarily exclusive access to the processes requesting the lock.

19 votes

Query hanging in ClientRead and blocking all others

You have a problem with transaction management. A session that waits for ClientRead is done processing the last query and waits for the client to send the next request. The only way that such a sessi …
Laurenz Albe's user avatar
  • 56.4k
8 votes
Accepted

ALTER TABLE … ADD COLUMN on a small table takes forever, pg_stat_activity doesn't show any q...

Somebody must hold a lock on the table, which means that you have an open transaction. That is a bug; no transaction should ever stay open. To find out which sessions block your statement: Before you …
Laurenz Albe's user avatar
  • 56.4k
6 votes
Accepted

Measuring how long PostgreSQL waits for locks

You can enable log_lock_waits to get information about sessions that have to wait more than deadlock_timeout for a lock. You can reduce deadlock_timeout to see shorter waits. Other than that, monitor …
Laurenz Albe's user avatar
  • 56.4k
6 votes
Accepted

How to check for row lock level when FOR UPDATE is used in PostgreSQL?

Row locks are not permanently stored in the shared lock table, but on the row itself, so you cannot simply query for them. To figure out which rows in a table are locked by concurrent transactions, yo …
Laurenz Albe's user avatar
  • 56.4k
4 votes

How can I set a column to NOT NULL without locking the table during a table scan?

I looked at the source code (function ATRewriteTable in src/backend/commands/tablecmds.c), and PostgreSQL always uses a sequential scan of the table to verify NOT NULL constraints. So creating indexe …
Laurenz Albe's user avatar
  • 56.4k
4 votes
Accepted

Postgresql INSERT stuck, what can cause this with no locks blocking

Nobody is blocked by a lock. The insert has finished long ago, but the application forgot to commit the transaction. That is an application error, and you should start investigating there. Processing …
Laurenz Albe's user avatar
  • 56.4k
4 votes
Accepted

Advisory locks: private to connected database or shared across cluster?

That is indeed not clear from the documentation, but a simple experiment shows that advisory locks are local to the database. That is, you can take the same advisory lock in two different databases wi …
Laurenz Albe's user avatar
  • 56.4k
4 votes
Accepted

How do we get around PostgreSQL autovacuum taking a table-level lock ACCESS EXCLUSIVE on rep...

One undocumented way of avoiding VACUUM truncation and the exclusive lock it requires is to set old_snapshot_threshold to a value other than -1. This in turn will get rid of the locks and the resultin …
Laurenz Albe's user avatar
  • 56.4k
3 votes

What is the difference between lock_timeout and deadlock_timeout?

The difference between a live lock (handled by lock_timeout) and a deadlock is that the latter is guaranteed never to end, because two (or more) sessions are waiting for each other. A live lock can a …
Laurenz Albe's user avatar
  • 56.4k
3 votes

How to lock entire Postgres table but allow reads

Explicitly locking tables is almost always the wrong thing to do. If you describe the use case in more detail, I am confident that a better solution can be found. … Locking tables frequently will keep autovacuum from doing its important work on the table, and eventually an anti-wraparound autovacuum job will come along and block you, bringing processing to a standstill …
Laurenz Albe's user avatar
  • 56.4k
3 votes
Accepted

PostgreSQL triggered update function lock mechanism

The magic is called "row lock". The updates on the counter column are serialized by row locks, so there cannot be any race condition. A lost update can never happen if you read and write the data in a …
Laurenz Albe's user avatar
  • 56.4k
3 votes
Accepted

What is the performance cost of enabling "log_lock_waits" on Postgres?

This is essentially for free, and you should enable it in all databases unless the workload is designed to have long lock waits regularly (which would be a design bug). These error messages are writt …
Laurenz Albe's user avatar
  • 56.4k
3 votes

Do I need an explicit FOR UPDATE lock in a CTE in UPDATE?

If you want to prevent concurrent statements from modifying the rows that the CTE selects before they get updated, you need to use SELECT ... FOR NO KEY UPDATE in the CTE.
Laurenz Albe's user avatar
  • 56.4k
2 votes

How to lock an entire Postgres database

Setting up a streaming replication standby server in PostgreSQL is much easier than that. Follow the documentation. MySQL is quite different from PostgreSQL when it comes to replication. A simple se …
Laurenz Albe's user avatar
  • 56.4k
2 votes
Accepted

Zabbix partitioning autovacuum causes locking

A normal autovacuum process will succumb silently if it blocks another transaction, but if that happens all the time and autovacuum can never finish, you will eventually have old table rows that have …
Laurenz Albe's user avatar
  • 56.4k

15 30 50 per page