[PATCH] pg_upgrade fails when postgres/template1 isn't in default tablespace

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] pg_upgrade fails when postgres/template1 isn't in default tablespace
Date: 2015-06-19 16:10:40
Message-ID: CABRT9RAz8uCV7xVVcuecWkBcdg8mN0mLqw1sV3naT4CDOYHVvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi list

One of my databases failed to upgrade successfully and produced this error
in the copying phase:

error while copying relation "pg_catalog.pg_largeobject"
("/srv/ssd/PG_9.3_201306121/1/12023" to "/PG_9.4_201409291/1/12130"): No
such file or directory

Turns out this happens when either the "postgres" or "template1" databases
have been moved to a non-default tablespace. pg_dumpall does not dump
attributes (such as tablespace) for these databases; pg_upgrade queries the
new cluster about the tablespace for these relations and builds a broken
destination path for the copy/link operation.

The least bad solution seems to be generating ALTER DATBASE SET TABLESPACE
commands for these from pg_dumpall. Previously a --globals-only dump didn't
generate psql \connect commands, but you can't run SET TABLESPACE from
within the same database you're connected to. So to move "postgres", it
needs to connect to "template1" and vice versa. That seems fine for the
purpose of pg_upgrade which can assume a freshly created cluster with both
databases intact.

I have implemented a proof of concept patch for this. Currently I'm only
tackling the binary upgrade failure and not general pg_dumpall.

Alternatively, we could allow SET TABLESPACE in the current database, which
seems less ugly to me. A code comment says "Obviously can't move the tables
of my own database", but it's not obvious to me why. If I'm the only
connected backend, it seems that any caches and open files could be
invalidated. But I don't know how big of an undertaking that would be.

----

While working on this, I also noticed other things that pg_dumpall (and
this pg_upgrade) misses:
* Nothing at all is dumped for the template0 database, although ACLs,
settings and the tablespace can be changed by the user
* template1 & postgres databases retain ACLs and settings, but not
attributes like TABLESPACE or CONNECTION LIMIT. Other attributes like
LC_COLLATE and LC_CTYPE can't be changed without recreating the DB, but
those don't matter for the pg_upgrade case anyway.

It seems those would be good material for another patch?

Regards,
Marti Raudsepp

Attachment Content-Type Size
0001-Fix-pg_upgrade-when-postgres-template1-aren-t-in-def.patch binary/octet-stream 1.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2015-06-19 16:56:21 Re: The real reason why TAP testing isn't ready for prime time
Previous Message Alvaro Herrera 2015-06-19 16:00:46 Re: Auto-vacuum is not running in 9.1.12