pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problem using pg_restore with -a option
3+ messages / 3 participants
[nested] [flat]

* Problem using pg_restore with -a option
@ 2006-09-01 14:40  Luís Sousa <llsousa@ualg.pt>
  0 siblings, 2 replies; 3+ messages in thread

From: Luís Sousa @ 2006-09-01 14:40 UTC (permalink / raw)
  To: pgsql-admin

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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problem using pg_restore with -a option
@ 2006-09-01 15:43  Alvaro Herrera <alvherre@commandprompt.com>
  parent: Luís Sousa <llsousa@ualg.pt>
  1 sibling, 0 replies; 3+ messages in thread

From: Alvaro Herrera @ 2006-09-01 15:43 UTC (permalink / raw)
  To: Luís Sousa <llsousa@ualg.pt>; +Cc: pgsql-admin

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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problem using pg_restore with -a option
@ 2006-09-01 16:02  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Luís Sousa <llsousa@ualg.pt>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2006-09-01 16:02 UTC (permalink / raw)
  To: Luís Sousa <llsousa@ualg.pt>; +Cc: pgsql-admin

=?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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-09-01 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-01 14:40 Problem using pg_restore with -a option Luís Sousa <llsousa@ualg.pt>
2006-09-01 15:43 ` Alvaro Herrera <alvherre@commandprompt.com>
2006-09-01 16:02 ` Tom Lane <tgl@sss.pgh.pa.us>

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