pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_dump and pg_restore and foreign keys
6+ messages / 2 participants
[nested] [flat]
* pg_dump and pg_restore and foreign keys
@ 2021-10-27 11:27 Tore Halvorsen <tore.halvorsen@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tore Halvorsen @ 2021-10-27 11:27 UTC (permalink / raw)
To: pgsql-general
Hi,
I hope this is the correct place for this question.
I'm trying to restore a database where adding foreign key constraints takes
most of the time. Does there exist a simple way to make either pg_dump or
pg_restore handle them as "not valid", and defer the validation.
--
Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
<demo> Tore Halvorsen || +052 0553034554
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pg_dump and pg_restore and foreign keys
@ 2021-10-27 13:27 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tore Halvorsen <tore.halvorsen@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-10-27 13:27 UTC (permalink / raw)
To: Tore Halvorsen <tore.halvorsen@gmail.com>; +Cc: pgsql-general
Tore Halvorsen <tore.halvorsen@gmail.com> writes:
> I'm trying to restore a database where adding foreign key constraints takes
> most of the time. Does there exist a simple way to make either pg_dump or
> pg_restore handle them as "not valid", and defer the validation.
No. It's kind of a neat idea perhaps, but it's not there. You could
* use parallel pg_restore to alleviate the pain, or
* use pg_restore's -l and -L switches to strip out the FKs altogether,
and then re-add them manually afterwards.
Or there's always
* hack the pg_dump source code to include NOT VALID. While a real
feature patch that made this optional would be a bit complicated,
doing it unconditionally should be a one-line change.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pg_dump and pg_restore and foreign keys
@ 2021-10-27 13:50 Tore Halvorsen <tore.halvorsen@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Tore Halvorsen @ 2021-10-27 13:50 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
That would be appending it for "pg_catalog.pg_get_constraintdef(oid) AS
condef" in getConstraints in pg_dump.c?
On Wed, Oct 27, 2021 at 3:27 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Tore Halvorsen <tore.halvorsen@gmail.com> writes:
> > I'm trying to restore a database where adding foreign key constraints
> takes
> > most of the time. Does there exist a simple way to make either pg_dump or
> > pg_restore handle them as "not valid", and defer the validation.
>
> No. It's kind of a neat idea perhaps, but it's not there. You could
>
> * use parallel pg_restore to alleviate the pain, or
>
> * use pg_restore's -l and -L switches to strip out the FKs altogether,
> and then re-add them manually afterwards.
>
> Or there's always
>
> * hack the pg_dump source code to include NOT VALID. While a real
> feature patch that made this optional would be a bit complicated,
> doing it unconditionally should be a one-line change.
>
> regards, tom lane
>
--
Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
<demo> Tore Halvorsen || +052 0553034554
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pg_dump and pg_restore and foreign keys
@ 2021-10-27 14:04 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tore Halvorsen <tore.halvorsen@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-10-27 14:04 UTC (permalink / raw)
To: Tore Halvorsen <tore.halvorsen@gmail.com>; +Cc: pgsql-general
Tore Halvorsen <tore.halvorsen@gmail.com> writes:
> That would be appending it for "pg_catalog.pg_get_constraintdef(oid) AS
> condef" in getConstraints in pg_dump.c?
No, you want to mess with the text printed by dumpConstraint().
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pg_dump and pg_restore and foreign keys
@ 2021-10-27 14:08 Tore Halvorsen <tore.halvorsen@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Tore Halvorsen @ 2021-10-27 14:08 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
Then I'll try that, thank you :)
On Wed, Oct 27, 2021 at 4:04 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Tore Halvorsen <tore.halvorsen@gmail.com> writes:
> > That would be appending it for "pg_catalog.pg_get_constraintdef(oid) AS
> > condef" in getConstraints in pg_dump.c?
>
> No, you want to mess with the text printed by dumpConstraint().
>
> regards, tom lane
>
--
Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
<demo> Tore Halvorsen || +052 0553034554
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pg_dump and pg_restore and foreign keys
@ 2021-10-29 05:57 Tore Halvorsen <tore.halvorsen@gmail.com>
parent: Tore Halvorsen <tore.halvorsen@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Tore Halvorsen @ 2021-10-29 05:57 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
In case someone else needs to do this - I ended up with this change in
pg_dump.c around lines 17080-17090
I guess a proper solution would check the already invalid foreign keys in a
different way.
appendPQExpBuffer(q, " ADD CONSTRAINT %s %s%s;\n",
fmtId(coninfo->dobj.name),
coninfo->condef
, dopt->foreign_keys_not_valid && !strstr(coninfo->condef, "NOT VALID") ? "
NOT VALID":"");
On Wed, Oct 27, 2021 at 4:08 PM Tore Halvorsen <tore.halvorsen@gmail.com>
wrote:
> Then I'll try that, thank you :)
>
> On Wed, Oct 27, 2021 at 4:04 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>> Tore Halvorsen <tore.halvorsen@gmail.com> writes:
>> > That would be appending it for "pg_catalog.pg_get_constraintdef(oid) AS
>> > condef" in getConstraints in pg_dump.c?
>>
>> No, you want to mess with the text printed by dumpConstraint().
>>
>> regards, tom lane
>>
>
>
> --
> Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
> <demo> Tore Halvorsen || +052 0553034554
>
--
Eld på åren og sol på eng gjer mannen fegen og fjåg. [Jøtul]
<demo> Tore Halvorsen || +052 0553034554
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-10-29 05:57 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 11:27 pg_dump and pg_restore and foreign keys Tore Halvorsen <tore.halvorsen@gmail.com>
2021-10-27 13:27 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-10-27 13:50 ` Tore Halvorsen <tore.halvorsen@gmail.com>
2021-10-27 14:04 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-10-27 14:08 ` Tore Halvorsen <tore.halvorsen@gmail.com>
2021-10-29 05:57 ` Tore Halvorsen <tore.halvorsen@gmail.com>
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