Re: heap vacuum & cleanup locks

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Jim Nasby <jim(at)nasby(dot)net>, Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: heap vacuum & cleanup locks
Date: 2011-11-02 22:19:56
Message-ID: CA+TgmoaR59WMK9mEaqvyNxkZDoeGz7JBkbqz8-FsVYVGUYZkUg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jun 7, 2011 at 3:24 PM, Greg Stark <gsstark(at)mit(dot)edu> wrote:
> Well it's super-exclusive-vacuum-lock avoidance techniques. Why
> shouldn't it make more sense to try to reduce the frequency and impact
> of the single-purpose outlier in a non-critical-path instead of
> burdening every other data reader with extra overhead?
>
> I think Robert's plan is exactly right though I would phrase it
> differently. We should get the exclusive lock, freeze/kill any xids
> and line pointers, then if the pin-count is 1 do the compaction.

I wrote a really neat patch to do this today... and then, as I
thought about it some more, I started to think that it's probably
unsafe. Here's the trouble: with this approach, we assume that it's
OK to change the contents of the line pointer while holding only an
exclusive lock on the buffer. But there is a good deal of code out
there that thinks it's OK to examine a line pointer with only a pin on
the buffer (no lock). You need a content lock to scan the item
pointer array, but once you've identified an item of interest, you're
entitled to assume that it won't be modified while you hold a buffer
pin. Now, if you've identified a particular tuple as being visible to
your scan, then you might think that VACUUM shouldn't be removing it
anyway. But I think that's only true for MVCC scans - for example,
what happens under SnapshotNow semantics? But then then on third
thought, if you've also got an MVCC snapshot taken before the start of
the SnapshotNow scan, you are probably OK, because your advertised
xmin should prevent anyone from removing anything anyway, so how do
you actually provoke a failure?

Anyway, I'm attaching the patch, in case anyone has any ideas on where
to go with this.

> I'm really wishing we had more bits in the vm. It looks like we could use:
>  - contains not-all-visible tuples
>  - contains not-frozen xids
>  - in need of compaction
>
> I'm sure we could find a use for one more page-level vm bit too.

We've got plenty of room for more page-level bits, if we need them.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
vacuum-unstick-v1.patch application/octet-stream 17.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2011-11-02 23:12:24 Re: Re: [COMMITTERS] pgsql: Force strings passed to and from plperl to be in UTF8 encoding.
Previous Message Andrew Dunstan 2011-11-02 22:02:39 Re: pg_dump --exclude-table-data