pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #15238: Sequence owner not updated when owning table is foreign
10+ messages / 7 participants
[nested] [flat]
* BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-06-12 13:21 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 10+ messages in thread
From: PG Bug reporting form @ 2018-06-12 13:21 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: christoph.berg@credativ.de
The following bug has been logged on the website:
Bug reference: 15238
Logged by: Christoph Berg
Email address: christoph.berg@credativ.de
PostgreSQL version: 10.4
Operating system: Debian
Description:
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:
create extension postgres_fdw;
create server pg foreign data wrapper postgres_fdw;
create foreign table a (a serial) server pg;
alter table a owner to postgres; -- some owner that is not the current
user
\d
List of relations
Schema │ Name │ Type │ Owner
────────┼─────────┼───────────────┼──────────
public │ a │ foreign table │ postgres
public │ a_a_seq │ sequence │ cbe -- original owner
pg_dump -s then emits a dump that cannot be restored:
...
CREATE FOREIGN TABLE public.a (
a integer NOT NULL
)
SERVER pg;
ALTER FOREIGN TABLE public.a OWNER TO postgres;
CREATE SEQUENCE public.a_a_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE public.a_a_seq OWNER TO cbe;
ALTER SEQUENCE public.a_a_seq OWNED BY public.a.a
-- ERROR: 55000: sequence must have same owner as table it is linked to
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-06-15 03:29 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 3 replies; 10+ messages in thread
From: Peter Eisentraut @ 2018-06-15 03:29 UTC (permalink / raw)
To: christoph.berg@credativ.de; pgsql-bugs@lists.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
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-06-15 03:40 Alvaro Herrera <alvherre@2ndquadrant.com>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2 siblings, 0 replies; 10+ messages in thread
From: Alvaro Herrera @ 2018-06-15 03:40 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: christoph.berg@credativ.de; pgsql-bugs@lists.postgresql.org
On 2018-Jun-14, Peter Eisentraut wrote:
> Also, can partitioned tables have serial columns? Are there more omissions?
You're right, this is wrong for partitioned tables too.
create table part (a serial) partition by range (a);
create table part2 partition of part for values from (1) to (1000);
create user foo;
alter table part owner to foo;
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-06-15 04:06 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2 siblings, 0 replies; 10+ messages in thread
From: Amit Langote @ 2018-06-15 04:06 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; christoph.berg@credativ.de; pgsql-bugs@lists.postgresql.org
On 2018/06/15 12:29, Peter Eisentraut wrote:
> 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.
+1 to recursing without a relkind check.
Thanks,
Amit
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-25 12:06 Christoph Berg <christoph.berg@credativ.de>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2 siblings, 1 reply; 10+ messages in thread
From: Christoph Berg @ 2018-09-25 12:06 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; +Cc: pgsql-bugs@lists.postgresql.org
Re: Peter Eisentraut 2018-06-15 <e3cf9eb8-add9-f523-b3f8-de657e091a14@2ndquadrant.com>
> 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.
Did that ever get applied? I can't find it in the git log.
Christoph
--
Senior Berater, Tel.: +49 2166 9901 187
credativ GmbH, HRB Mönchengladbach 12080, USt-ID-Nummer: DE204566209
Trompeterallee 108, 41189 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer
Datenschutzerklärung: https://www.credativ.de/datenschutz
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-26 00:09 Michael Paquier <michael@paquier.xyz>
parent: Christoph Berg <christoph.berg@credativ.de>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2018-09-26 00:09 UTC (permalink / raw)
To: Christoph Berg <christoph.berg@credativ.de>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs@lists.postgresql.org
On Tue, Sep 25, 2018 at 02:06:35PM +0200, Christoph Berg wrote:
> Did that ever get applied? I can't find it in the git log.
Not that I can see. I have added an entry for old bugs on the v11 list
of open items. Peter, could you finish wrapping it or do you need some
help?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-26 18:53 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Peter Eisentraut @ 2018-09-26 18:53 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; Christoph Berg <christoph.berg@credativ.de>; +Cc: Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs@lists.postgresql.org
On 26/09/2018 02:09, Michael Paquier wrote:
> On Tue, Sep 25, 2018 at 02:06:35PM +0200, Christoph Berg wrote:
>> Did that ever get applied? I can't find it in the git log.
>
> Not that I can see. I have added an entry for old bugs on the v11 list
> of open items. Peter, could you finish wrapping it or do you need some
> help?
Committed and backpatched now.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-26 22:35 Michael Paquier <michael@paquier.xyz>
parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 10+ messages in thread
From: Michael Paquier @ 2018-09-26 22:35 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Christoph Berg <christoph.berg@credativ.de>; Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs@lists.postgresql.org
On Wed, Sep 26, 2018 at 08:53:44PM +0200, Peter Eisentraut wrote:
> Committed and backpatched now.
Thanks, Peter.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-26 23:52 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 10+ messages in thread
From: Tom Lane @ 2018-09-26 23:52 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Christoph Berg <christoph.berg@credativ.de>; Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs@lists.postgresql.org
Michael Paquier <michael@paquier.xyz> writes:
> On Wed, Sep 26, 2018 at 08:53:44PM +0200, Peter Eisentraut wrote:
>> Committed and backpatched now.
> Thanks, Peter.
Should the entry on the v11 Open Items list be closed now?
regards, tom lane
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: BUG #15238: Sequence owner not updated when owning table is foreign
@ 2018-09-27 03:11 Michael Paquier <michael@paquier.xyz>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 10+ messages in thread
From: Michael Paquier @ 2018-09-27 03:11 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Christoph Berg <christoph.berg@credativ.de>; Alvaro Herrera <alvherre@2ndquadrant.com>; Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>; pgsql-bugs@lists.postgresql.org
On Wed, Sep 26, 2018 at 07:52:04PM -0400, Tom Lane wrote:
> Should the entry on the v11 Open Items list be closed now?
Done already (not by me, by Justin).
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2018-09-27 03:11 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 13:21 BUG #15238: Sequence owner not updated when owning table is foreign PG Bug reporting form <noreply@postgresql.org>
2018-06-15 03:29 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2018-06-15 03:40 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2018-06-15 04:06 ` Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
2018-09-25 12:06 ` Christoph Berg <christoph.berg@credativ.de>
2018-09-26 00:09 ` Michael Paquier <michael@paquier.xyz>
2018-09-26 18:53 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2018-09-26 22:35 ` Michael Paquier <michael@paquier.xyz>
2018-09-26 23:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-09-27 03:11 ` Michael Paquier <michael@paquier.xyz>
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