Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: file-locking and postmaster.pid


  • From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
  • To: korry <korry(at)appx(dot)com>
  • Cc: pgsql-hackers(at)postgresql(dot)org
  • Subject: Re: file-locking and postmaster.pid
  • Date: Wed, 24 May 2006 16:34:40 -0400
  • Message-id: <20060524203440(dot)GA6607(at)surnet(dot)cl>

korry wrote:

> > The Win32 API for locking seems mighty strange to me.
> 
> Linux/Unix byte locking is advisory (meaning that one lock can block
> another lock, but it can't block a read).

No -- it is advisory meaning that a process that does not try to acquire
the lock is not locked out.  You can certainly block a file in exclusive
mode, using the LOCK_EX flag.  (And at least on my Linux system, there
is mandatory locking too, using the fcntl() interface).

I think the next question is -- how would the lock interface be used?
We could acquire an exclusive lock on postmaster start (to make sure no
backend is running), then reduce it to a shared lock.  Every backend
would inherit the shared lock.  But the lock exchange is not guaranteed
to be atomic so a new postmaster could start just after we acquire the
lock and acquire the shared lock.  It'd need to be complemented with
another lock.

> Win32 locking is mandatory (at least in the most portable form) so a
> lock blocks a reader.

There is also shared/exclusive locking of a file on Win32.  My comment
weas more directed at the fact that you have to "create some sort of
lock handle" from a file handle and then lock the lock handle, or
something like that.  I don't recall the exact details but it was
strange (as opposed to just open and then flock).

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group