Re: vac_update_datfrozenxid will raise "wrong tuple length" if pg_database tuple contains toast attribute.

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Junfeng Yang <yjerome(at)vmware(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Ashwin Agrawal <aashwin(at)vmware(dot)com>
Subject: Re: vac_update_datfrozenxid will raise "wrong tuple length" if pg_database tuple contains toast attribute.
Date: 2020-11-25 07:12:15
Message-ID: X74Dz5MmFG5/I2Wv@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 18, 2020 at 06:32:51AM +0000, Junfeng Yang wrote:
> A path is attached co auther by Ashwin Agrawal, the solution is to
> fetch the pg_database tuple from disk instead of system cache if
> needed.

Yeah, we had better fix and I guess backpatch something here. That's
annoying.

+DROP DATABASE IF EXISTS vacuum_freeze_test;
+NOTICE: database "vacuum_freeze_test" does not exist, skipping
+CREATE DATABASE vacuum_freeze_test;
This test is costly. Extracting that into a TAP test would be more
adapted, still I am not really convinced that this is a case worth
spending extra cycles on.

+ tuple = systable_getnext(sscan);
+ if (HeapTupleIsValid(tuple))
+ tuple = heap_copytuple(tuple);
That's an unsafe pattern as the tuple scanned could finish by being
invalid.

One thing that strikes me as unwise is that we could run into similar
problems with vac_update_relstats() in the future, and there have been
recent talks about having more toast tables like for pg_class. That
is not worth caring about on stable branches because it is not an
active problem there, but we could do something better on HEAD.

+ /* Get the pg_database tuple to scribble on */
+ cached_tuple = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
+ cached_dbform = (Form_pg_database) GETSTRUCT(cached_tuple);
Er, shouldn't we *not* use the system cache at all here then? Or am I
missing something obvious? Please see the attached, that is more
simpleg.
--
Michael

Attachment Content-Type Size
pg_database-vacuum-v2.patch text/x-diff 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kasahara Tatsuhito 2020-11-25 07:18:19 Re: autovac issue with large number of tables
Previous Message Peter Eisentraut 2020-11-25 07:06:57 Re: default result formats setting