Unix Technical Forum

Problem using pg_restore with -a option

This is a discussion on Problem using pg_restore with -a option within the pgsql Admins forums, part of the PostgreSQL category; --> Hi all, I'm using PostgreSQL 7.4.7-6sarge2 (debian) Using the schema below, doing a pg_dump -Fc, delete all data, and ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 07:34 AM
=?ISO-8859-1?Q?Lu=EDs_Sousa?=
 
Posts: n/a
Default Problem using pg_restore with -a option

Hi all,

I'm using PostgreSQL 7.4.7-6sarge2 (debian)

Using the schema below, doing a pg_dump -Fc, delete all data, and a
pg_restore -a, the sequence of inserting data isn't correct issuing an
error.
Could this be a bug?

Notice that on schema, table periodo depends on tipo, but the sequence
is table periodo, then table tipo and after table periodo is changed to
reference tipo.

My schema file:
drop table periodo cascade ;
drop table tipo cascade ;

create table periodo (
"idPeriodo" serial not null,
"idTipo" int4,
designacao varchar(50),
constraint pk_Periodo primary key ("idPeriodo")
) ;

create table tipo (
"idTipo" serial not null,
tipo varchar(5),
designacao varchar(50),
constraint pk_Tipo primary key ("idTipo")
) ;

alter table periodo add constraint fk_tipo
foreign key ("idTipo")
references tipo ("idTipo") ;

My data on tables:
INSERT INTO tipo (tipo,designacao) VALUES ('T','Type');
INSERT INTO periodo ("idTipo",designacao) VALUES (1,'periodo');

Error:
pg_restore: ERROR: insert or update on table "periodo" violates foreign
key constraint "fk_tipo"
DETAIL: Key (idTipo)=(1) is not present in table "tipo".

Best regards,
Luís Sousa



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 07:34 AM
Alvaro Herrera
 
Posts: n/a
Default Re: Problem using pg_restore with -a option

Luís Sousa wrote:
> Hi all,
>
> I'm using PostgreSQL 7.4.7-6sarge2 (debian)
>
> Using the schema below, doing a pg_dump -Fc, delete all data, and a
> pg_restore -a, the sequence of inserting data isn't correct issuing an
> error.
> Could this be a bug?


Not a bug -- rather a known deficiency. pg_dump 8.0 and beyond knows
how to sort stuff so that these problems do not occur, but 7.4 doesn't.

The typical workaround was to use pg_restore -l/-L to generate the list
of objects to restore and sort them appropiately, then do the actual
restore.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 07:34 AM
Tom Lane
 
Posts: n/a
Default Re: Problem using pg_restore with -a option

=?ISO-8859-1?Q?Lu=EDs_Sousa?= <llsousa@ualg.pt> writes:
> Using the schema below, doing a pg_dump -Fc, delete all data, and a
> pg_restore -a, the sequence of inserting data isn't correct issuing an
> error.


Data-only restores make no attempt to avoid foreign-key constraint
problems --- in general there is no solution, since you could have
circular constraints.

You could drop and re-add the FK constraints, or if you trust that the
data is valid there's the --disable-triggers option to suppress FK
constraint checking.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com