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 21:35:02
Message-ID: 20060524213502.GC7412@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

korry wrote:

> > 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.
>
> You never need to reduce it to a shared lock. On postmaster startup,
> try to lock the sentinel byte (one byte past the end-of-file). If you
> can lock it, you know that no other postmaster has that byte locked. If
> you can't lock it, another postmaster is running. It is an atomic
> operation.

This doesn't work if the postmaster dies but a backend continues to run,
which is arguably the most important case we need to protect against.

> However, Tom may be correct about NFS locking, but I guess I'm surprised
> that anyone would care :-)

Quite a lot of people run NFS-mounted data directories ...

--
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 Jim C. Nasby 2006-05-24 21:40:18 Re: Compression and on-disk sorting
Previous Message Alvaro Herrera 2006-05-24 21:33:06 Re: file-locking and postmaster.pid