Re: Pg_upgrade and toast tables bug discovered

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Pg_upgrade and toast tables bug discovered
Date: 2014-07-07 15:24:51
Message-ID: CA+TgmoYE3+17p-sPJs0zvX6bNEXoBopeZC+J8AEpogxcfdf-xQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 4, 2014 at 11:12 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> On Fri, Jul 4, 2014 at 12:01:37AM -0400, Bruce Momjian wrote:
>> > The most robust, but not trivial, approach seems to be to prevent toast
>> > table creation if there wasn't a set_next_toast_pg_class_oid(). Then,
>> > after all relations are created, iterate over all pg_class entries that
>> > possibly need toast tables and recheck if they now might need one.
>>
>> Wow, that is going to be kind of odd in that there really isn't a good
>> way to create toast tables except perhaps add a dummy TEXT column and
>> remove it. There also isn't an easy way to not create a toast table,
>> but also find out that one was needed. I suppose we would have to
>> insert some dummy value in the toast pg_class column and come back later
>> to clean it up.
>>
>> I am wondering what the probability of having a table that didn't need a
>> toast table in the old cluster, and needed one in the new cluster, and
>> there being an oid collision.
>>
>> I think the big question is whether we want to go down that route.
>
> Here is an updated patch. It was a little tricky because if the
> mismatched non-toast table is after the last old relation, you need to
> test differently and emit a different error message as there is no old
> relation to complain about.
>
> As far as the reusing of oids, we don't set the oid counter until after
> the restore, so any new unmatched toast table would given a very low
> oid. Since we restore in oid order, for an oid to be assigned that was
> used in the old cluster, it would have to be a very early relation, so I
> think that reduces the odds considerably. I am not inclined to do
> anything more to avoid this until I see an actual error report ---
> trying to address it might be invasive and introduce new errors.

That sounds pretty shaky from where I sit. I wonder if the
pg_upgrade_support module should have a function
create_toast_table_if_needed(regclass) or something like that. Or
maybe just create_any_missing_toast_tables(), iterating over all
relations.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-07-07 15:51:13 Re: [RFC: bug fix?] Connection attempt block forever when the synchronous standby is not running
Previous Message Tom Lane 2014-07-07 14:07:19 Re: Extending constraint exclusion for implied constraints/conditions