Re: locks held during commit with synchronous replication

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: locks held during commit with synchronous replication
Date: 2013-10-21 18:46:24
Message-ID: 2456.1382381184@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?ISO-8859-1?Q?Torsten_F=F6rtsch?= <torsten(dot)foertsch(at)gmx(dot)net> writes:
> I noticed that with synchronous replication I often see locks like this:
> [ AccessExclusiveLock on "database 0" ]

You did not say what PG version you're talking about, but if it's recent
then this must be coming from PreCommit_Notify, which takes such a lock
while pushing entries into the shared notification-event queue:

/*
* Serialize writers by acquiring a special lock that we hold till
* after commit. This ensures that queue entries appear in commit
* order, and in particular that there are never uncommitted queue
* entries ahead of committed ones, so an uncommitted transaction
* can't block delivery of deliverable notifications.
*
* We use a heavyweight lock so that it'll automatically be released
* after either commit or abort. This also allows deadlocks to be
* detected, though really a deadlock shouldn't be possible here.
*
* The lock is on "database 0", which is pretty ugly but it doesn't
* seem worth inventing a special locktag category just for this.
* (Historical note: before PG 9.0, a similar lock on "database 0" was
* used by the flatfiles mechanism.)
*/
LockSharedObject(DatabaseRelationId, InvalidOid, 0,
AccessExclusiveLock);

This has nothing to do with synchronous replication, only with use of
LISTEN/NOTIFY.

> Does that mean that only one transaction can be committed at a time?

If they're sending notifies, yes.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-10-21 18:53:49 Re: Bug? Function with side effects not evaluated in CTE
Previous Message David Johnston 2013-10-21 18:12:34 Re: Upgrade from 9.1 to 9.10