Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm fairly new to postgresql. I've checked out the documentation and I can't find anything about how to do page-level locking.

I understand that I can set a table into a locking mode like this: LOCK TABLE myTable IN LOCKMODE ROW EXCLUSIVE;

How would I implement page level locking for my session? Let me know if it seems that I have a misunderstanding of the fundamentals.

share|improve this question
PostgreSQL doesn't have page level locking. – Frank Heikens Dec 1 '12 at 21:39
Actually, Postgres does have page-level locking, related to shared buffer pool. But this is an internal matter that should be transparent to application developers. See section 13.3.3 of current doc page, Explicit Locking. – Basil Bourque May 30 '15 at 7:00
up vote 3 down vote accepted

Why would you want to do explicit page level locking? You don't control what is on each page, so you'd be locking some arbitrary collection of data. What purpose would that serve?

I think you're looking for row-level locking, which is accomplished using SELECT ... FOR UPDATE or SELECT ... FOR SHARE.

PostgreSQL upgrades row-level locks to page-level locks internally in a few places like serializable snapshot predicate tracking, buffer management, etc. It'll do this when there are too many row level locks and they're becoming a performance issue. You don't need to care about this, as this will have almost no effect on you at the SQL level. Normal row locks - as acquired by UPDATE, DELETE, SELECT ... FOR UPDATE, SELECT ... FOR SHARE etc - are AFAIK never upgraded to page-level locks, as doing so would increase the probability of deadlocks.

If you're really convinced you want page-level locking, please explain what problem you're trying to solve in more detail and why row-level or table-level locking don't do the job.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.