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: 2006-05-24 20:34:40
Message-ID: 20060524203440.GA6607@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-05-24 20:34:47 Re: file-locking and postmaster.pid
Previous Message Andrew Dunstan 2006-05-24 20:30:12 Re: file-locking and postmaster.pid