pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: christoph.berg@credativ.de
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15238: Sequence owner not updated when owning table is foreign
Date: Thu, 14 Jun 2018 23:29:19 -0400
Message-ID: <e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com> (raw)
In-Reply-To: <152880968046.32363.3930397030469114276@wrigleys.postgresql.org>
References: <152880968046.32363.3930397030469114276@wrigleys.postgresql.org>

On 6/12/18 09:21, PG Bug reporting form wrote:
> If a foreign table has a sequence attached (e.g. if the foreign table has a
> "serial" column), and the foreign table owner is updated, the sequence owner
> is not updated, leading to errors on restore:

Yup, it only recurses to sequences for regular tables and materialized
views.  I suggest to remove the relkind check altogether.  See attached
patch.

Can materialized views even have serial columns?  I suspect materialized
views entered this conditional because of the toast table check nearby.

Also, can partitioned tables have serial columns?  Are there more omissions?

So fewer relkind enumerations are probably better.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Recurse-to-sequences-on-ownership-change-for-all-rel.patch (text/plain, 2.1K) download From fb60f0e429608e29e112b37790c8a41413bc4787 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter_e@gmx.net> Date: Thu, 14 Jun 2018 23:22:14 -0400 Subject: [PATCH] Recurse to sequences on ownership change for all relkinds When a table ownership is changed, we must apply that also to any owned sequences. (Otherwise, it would result in a situation that cannot be restored, because linked sequences must have the same owner as the table.) But this was previously only applied to regular tables and materialized views. But it should also apply to at least foreign tables. This patch removes the relkind check altogether, because it doesn't save very much and just introduces the possibility of similar omissions. Bug: #15238 Reported-by: Christoph Berg <christoph.berg@credativ.de> --- src/backend/commands/tablecmds.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8b848f91a7..1bc3d8d748 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10455,17 +10455,13 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock list_free(index_oid_list); } - if (tuple_class->relkind == RELKIND_RELATION || - tuple_class->relkind == RELKIND_MATVIEW) - { - /* If it has a toast table, recurse to change its ownership */ - if (tuple_class->reltoastrelid != InvalidOid) - ATExecChangeOwner(tuple_class->reltoastrelid, newOwnerId, - true, lockmode); + /* If it has a toast table, recurse to change its ownership */ + if (tuple_class->reltoastrelid != InvalidOid) + ATExecChangeOwner(tuple_class->reltoastrelid, newOwnerId, + true, lockmode); - /* If it has dependent sequences, recurse to change them too */ - change_owner_recurse_to_sequences(relationOid, newOwnerId, lockmode); - } + /* If it has dependent sequences, recurse to change them too */ + change_owner_recurse_to_sequences(relationOid, newOwnerId, lockmode); } InvokeObjectPostAlterHook(RelationRelationId, relationOid, 0); -- 2.17.1

view thread (10+ messages)  latest in thread

Message-ID: <e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com>
Permalink:  ../e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com/
Also on:    postgresql.org/message-id/e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: peter.eisentraut@2ndquadrant.com, christoph.berg@credativ.de
  Subject: Re: BUG #15238: Sequence owner not updated when owning table is foreign
  In-Reply-To: <e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com>
  References: <152880968046.32363.3930397030469114276@wrigleys.postgresql.org> <e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox