Re: Avoid duplicated rows when restoring data from pg_dumpall ??

From: Pablo Alonso-Villaverde Roza <pavroza(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Avoid duplicated rows when restoring data from pg_dumpall ??
Date: 2009-08-26 07:01:38
Message-ID: fbd3fefa0908260001k126e0ad7p23e58b3975d54a0c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi Tom, thanks for your fast reply,

- As regards the duplicated rows, no, I don't get duplicated rows in all the
tables stored in the database because
some tables have primary-keys (and/or UNIQUE) constraints. These constraints
don't allow the restore process to
duplicate rows. In fact, it is a kind of "solution" I've tried...(add an
extra column with a primary-key or unique constraint, to this tables), and
it "works". The restore process doesn't generate duplicated rows, because
the constraint does not allow the insertion
of new duplicated data. Anyway..it looks like a kind of 'poor solution'
:-)

- Ok, thanks for the info, I thought pg_dumpall would work as I desired even
on non-empty clusters.
Of course...if there is no previous data, the restore process will never
create duplicated rows.

- Yes, the restore process generates errors, because it tries to re-generate
data structures that exist in the database server
at that moment. Even if I delete my own databases, some errors will appear
(because I cannot delete the internal stuff of
of the server -> the 'postgres' database for example) . Those errors, could
be ignored in most cases I think, but perhaps create a kind of "bad feeling"
about the result of the restore process, or can "hide" other more important
errors when you get a huge ammount of info on the screen either.

- I forgot to mention it. I'm using PostgreSQL 8.3 on Windows xp.

Thanks a lot for your advices,

Regards, Pablo

2009/8/24 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

> Pablo Alonso-Villaverde Roza <pavroza(at)gmail(dot)com> writes:
> > I'm getting duplicated rows in some of my tables when I try to restore
> data
> > from a dump file generated with 'pg_dumpall'.
>
> Probably all of them, actually ...
>
> > The only "way" I have found to solve this problem is deleting my database
> > before restoring the data, so everything is 're-created' in the restore
> > process without generating duplicated rows.
>
> A pg_dumpall script expects to be restored into an empty cluster. This
> is not a bug.
>
> > I thought, that the "-c" flag on pg_dumpall would force a DROP of any
> > previous data structures on the server but...it looks like it doesn't
> work
> > as I expected and ...when I restore data I get duplicated rows.
>
> The -c flag should cause the script to DROP all your databases first.
> But that switch has been known to have bugs in the past, and in any case
> it could fail if there are other sessions connected to those databases.
> Did you pay attention to whether the restore reported any errors?
> What PG version is this?
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message idris khanafi 2009-08-26 09:09:51 Partitions Table
Previous Message Patrick 2009-08-25 23:01:55 Re: Primary key on existing table?