CLUSTER vs toast vacuuming: there's still a problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: CLUSTER vs toast vacuuming: there's still a problem
Date: 2011-04-30 18:22:38
Message-ID: 1335.1304187758@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I thought some more about the bug #5998 business, and I believe there's
still a risk unaddressed by yesterday's patch. Suppose that we begin
a CLUSTER operation on some table, and then while it's running (perhaps
in the sort stage) autovacuum decides to vacuum the table's TOAST table.
The autovacuum could then have a later OldestXmin than the CLUSTER does.
This means that it could see as DEAD, and remove, toast tuples belonging
to main-table tuples that the CLUSTER thinks are RECENTLY_DEAD. Ooops.

This is only a risk because autovacuum processes a toast table
independently from its main table, and (so far as I can see)
doesn't take any lock on the main table while doing so.

We could fix the immediate problem by having CLUSTER take out a
vacuum-conflicting lock on the toast table before it determines the
OldestXmin it will use. I wonder though if it wouldn't be smarter
to insist that autovacuum acquire some lock on the main table
when processing a toast table. Without that, we could see this
type of problem again. (But on the third hand, locking toast table
and then main table is no good because of deadlock risks. And a
manual VACUUM on the toast table would be hazardous anyway.)

Thoughts?

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2011-04-30 18:58:45 Large Objects versus transactional behavior
Previous Message Gabriele Bartolini 2011-04-30 18:19:36 Proposed patch: Smooth replication during VACUUM FULL