pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Simon Riggs <simon@2ndQuadrant.com>
Cc: Ryan Kelly <rpkelly22@gmail.com>
Cc: tom Tom <tom@tomforb.es>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6629: Creating a gist index fails with "too many LWLocks taken"
Date: Fri, 11 May 2012 19:48:53 +0300
Message-ID: <4FAD42F5.9060706@enterprisedb.com> (raw)
In-Reply-To: <CA+U5nMK29jWExz52_3QoetJLmO1+Gz9__3SjZG=4P3nFh1qPJg@mail.gmail.com>
References: <E1SQkyu-0004nP-IW@wrigleys.postgresql.org>
	<4FA7EC37.5070703@enterprisedb.com>
	<CAFNZOJM4OpDN562BDS5g6iJX+NOjTwPUXtfQg91ALVH60td5vg@mail.gmail.com>
	<20120508011540.GA28140@llserver.lakeliving.com>
	<4FACE4C7.6070306@enterprisedb.com>
	<CA+U5nM+QzrhLM9V2Lwk2zqDEbTjwN-Y8nT6=kMDWibBwyiW_gg@mail.gmail.com>
	<4FAD1EC1.2000502@enterprisedb.com>
	<CA+U5nMK29jWExz52_3QoetJLmO1+Gz9__3SjZG=4P3nFh1qPJg@mail.gmail.com>

On 11.05.2012 18:18, Simon Riggs wrote:
> On 11 May 2012 15:14, Heikki Linnakangas
> <heikki.linnakangas@enterprisedb.com>  wrote:
>> On 11.05.2012 16:56, Simon Riggs wrote:
>>>
>>> On 11 May 2012 11:07, Heikki Linnakangas
>>> <heikki.linnakangas@enterprisedb.com>    wrote:
>>>
>>>> I wonder if we should reserve a few of the lwlock "slots" for critical
>>>> sections, to make this less likely to happen. Not only in this case, but
>>>> in
>>>> general. We haven't seen this problem often, but it would be quite
>>>> trivial
>>>> to reserve a few slots.
>>>
>>>
>>> Why reserve them solely for critical sections?
>>
>> Because if you run out of lwlocks in a critical section, you get a PANIC.
>
> Yes, but why reserve them solely for critical sections? If you have an
> escape hatch you use it, always

Well, no, because a PANIC is much worse than an ERROR. Think of this as 
a spare oxygen tank while diving, rather than an escape hatch. A spare 
tank can save your life if you run out of oxygen while ascending, but if 
you run out of oxygen on the way down, you don't continue going down 
with just the spare tank.

Imagine that you have a process that does something like this:

for (i=0; i < 99; i++)
   LWLockAcquire(foolock[i])

START_CRIT_SECTION();

XLogInsert(...)

END_CRIT_SECTION();

What happens at the moment is that XLogInsert hits the limit when it 
tries to acquire WALInsertLock, so you get a PANIC. If we reserved, say, 
5 locks for critical sections, so that you could hold 95 locks while 
outside a critical section, and 5 more within on, you would get an error 
earlier, outside the critical section, while acquiring the "foolocks". 
Or if the number of foolocks acquired was less than 95, you would not 
get error at all. That avoids the PANIC.

You can argue for just raising the limit, but that just moves the 
problem around. It's still possible to hit the limit within a critical 
section, and PANIC. Likewise, if we lower the limit, that helps us find 
the problems earlier in the development cycle, but doesn't change the 
fact that if you run too close to the edge, you run out of locks within 
a critical section and PANIC.

Of course, nothing stops you from writing (bad) code that acquires a lot 
of locks within a critical section, in which case you're screwed anyway.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com



view thread (18+ messages)  latest in thread

Message-ID: <4FAD42F5.9060706@enterprisedb.com>
Permalink:  ../4FAD42F5.9060706@enterprisedb.com/
Also on:    postgresql.org/message-id/4FAD42F5.9060706@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: heikki.linnakangas@enterprisedb.com, simon@2ndQuadrant.com, rpkelly22@gmail.com, tom@tomforb.es
  Subject: Re: BUG #6629: Creating a gist index fails with "too many LWLocks taken"
  In-Reply-To: <4FAD42F5.9060706@enterprisedb.com>
  References: <E1SQkyu-0004nP-IW@wrigleys.postgresql.org> <4FA7EC37.5070703@enterprisedb.com> <CAFNZOJM4OpDN562BDS5g6iJX+NOjTwPUXtfQg91ALVH60td5vg@mail.gmail.com> <20120508011540.GA28140@llserver.lakeliving.com> <4FACE4C7.6070306@enterprisedb.com> <CA+U5nM+QzrhLM9V2Lwk2zqDEbTjwN-Y8nT6=kMDWibBwyiW_gg@mail.gmail.com> <4FAD1EC1.2000502@enterprisedb.com> <CA+U5nMK29jWExz52_3QoetJLmO1+Gz9__3SjZG=4P3nFh1qPJg@mail.gmail.com> <4FAD42F5.9060706@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox