pg_upgrade bug in handling postgres/template1 databases - Mailing list pgsql-hackers

From Bruce Momjian
Subject pg_upgrade bug in handling postgres/template1 databases
Date
Msg-id 20150210175233.GB18557@momjian.us
Whole thread Raw
Responses Re: pg_upgrade bug in handling postgres/template1 databases  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers
I received a private pg_upgrade bug report related to its affect on the
removal of clog files in the upgraded cluster.  The user reported that
an upgraded cluster yielded this error very soon after being started for
the first time:

    SELECT * FROM test;
    ERROR:  could not access status of transaction 685
    DETAIL:  Could not open file "pg_clog/0000": No such file or directory.

I was confused as I had never seen such a report before.  After much
digging, I found out that the user was storing data _only_ in the
'postgres' database, not any other databases, and that pg_upgrade was
not preserving pg_database.datfrozenxid and pg_database.datminmxid, even
though it was processing those databases and copying over any user
tables and indexes.

When the new server was started, pg_database.datminmxid equaled the
current transaction counter and old clog files were removed, yielding
the error.

This is not a problem for users who store functions or extensions in the
postgres or template1 database, just user tables and indexes.

The attached patch fixes the problem, and I have reproduced the bug and
verified the patch fixes it.  It would have been nice if I had figured
this out two weeks ago, before we released minor version upgrades.  This
bug has existed back to 9.0 or earlier, so it isn't new.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: RangeType internal use
Next
From: Bruce Momjian
Date:
Subject: Re: Better error message on pg_upgrade checksum mismatches