Re: pg_dump/pg_restore schema and data separately and foreign key constraints - Mailing list pgsql-general

From Adrian Klaver
Subject Re: pg_dump/pg_restore schema and data separately and foreign key constraints
Date
Msg-id 656571287.5079541242163021955.JavaMail.root@sz0030a.emeryville.ca.mail.comcast.net
Whole thread Raw
In response to pg_dump/pg_restore schema and data separately and foreign key constraints  (Vasiliy Vasin <vasi3854@yandex.ru>)
Responses Re: pg_dump/pg_restore schema and data separately and foreign key constraints
List pgsql-general

----- "Vasiliy Vasin" <vasi3854@yandex.ru> wrote:

> I have database on production server that backups every day. Database
> is not big ~ 10mb.
> But I added several tables that takes big capacity and I don't want to
> backup data from them.
>
> So, I backup my database in two files: schema and data:
> pg_dump -s -E utf-8 -f ${filename.schema} -F custom -n public -O -Z 9
> -h ${connection.hostname} -U ${connection.username}
> ${connection.database}
> pg_dump -a -T table1 -T table2-E utf-8 -f ${filename.data} -F custom
> -n public -O -Z 9 -h ${connection.hostname} -U ${connection.username}
> ${connection.database}
>
> Then I tried to restore this backups:
> pg_restore -s -d ${connection.database} -h ${connection.hostname} -U
> ${connection.username} -O -F custom ${schemaFileName}
> pg_restore -a -d ${connection.database} -h ${connection.hostname} -U
> ${connection.username} -O -F custom ${dataFileName}
>
> Schema backup restored successfully.
>
> But then I restoring data backup I receiving errors like:
> COPY failed: ERROR:  insert or update on table "sometable" violates
> foreign key constraint "bla-blah"
>
> I tried -1 option for pg_restore, it not helps.
>
> I think this is common problem, but I don't found answer in google,
> only questions... :(
>


Sounds like an ordering problem, you are restoring the child table before the parent. Best bet is to dump the table
datato individual files and restore them in the proper order. 

Adrian Klaver
aklaver@comcast.net

pgsql-general by date:

Previous
From: Vasiliy Vasin
Date:
Subject: pg_dump/pg_restore schema and data separately and foreign key constraints
Next
From: Alan Hodgson
Date:
Subject: Re: pg_dump/pg_restore schema and data separately and foreign key constraints