pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Burgess, Freddie <FBurgess@radiantblue.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: pg_restore PostgreSQL 9.3.3 problems
Date: Fri, 13 Jun 2014 11:51:40 -0400
Message-ID: <27138.1402674700@sss.pgh.pa.us> (raw)
In-Reply-To: <3BBE635F64E28D4C899377A61DAA9FE02E2F3B84@NBSVR-MAIL01.radiantblue.local>
References: <3BBE635F64E28D4C899377A61DAA9FE02E2F1B17@NBSVR-MAIL01.radiantblue.local>
	<30170.1402621768@sss.pgh.pa.us>
	<3BBE635F64E28D4C899377A61DAA9FE02E2F3B84@NBSVR-MAIL01.radiantblue.local>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"Burgess, Freddie" <FBurgess@radiantblue.com> writes:
> This is the workflow ... 

> 1.) I execute the pg_dump; with every table in the schema leveraging the -t option, including the tracker_message table that has 99000 rows

> trackdb=# 
> trackdb=# select count(*) from tracker_message;
>  count 
> -------
>  99000
> (1 row)

> 2.) then, somehow a user deletes by mistake some data, 1000 rows for example.

> trackdb=# delete from tracker_message where id in (select id from tracker_message limit 1000);
> DELETE 1000
> trackdb=# select count(*) from tracker_message;
>  count 
> -------
>  98000
> (1 row)

> 3.) Now I want leverage pg_restore to recover the 1000 rows deleted,

Sorry, pg_dump/pg_restore aren't designed to solve such a problem.
Even just from the data standpoint, they don't do partial restores
within a table: they can only try to insert all of the rows that
were in the table at dump time.  So it's not surprising you'd get
pkey violations when you try that.  As you say, you could truncate
away all the data in tracker_message, but given all the foreign key
relationships that's going to be a mess.  Not to mention that you'd
lose updates made since the dump.

The -c option is entirely irrelevant to this; that's about dropping
and recreating whole tables, certainly not what you want here.

What I'd try doing is to load the old data into a temporary table and
then copy over just rows that no longer exist in tracker_message,
along the lines of

      insert into tracker_message
        select * from old_tracker_message o
	  where not exists (select 1 from tracker_message t where t.id=o.id);

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <27138.1402674700@sss.pgh.pa.us>
Permalink:  ../27138.1402674700@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27138.1402674700@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, FBurgess@radiantblue.com
  Subject: Re: pg_restore PostgreSQL 9.3.3 problems
  In-Reply-To: <27138.1402674700@sss.pgh.pa.us>
  References: <3BBE635F64E28D4C899377A61DAA9FE02E2F1B17@NBSVR-MAIL01.radiantblue.local> <30170.1402621768@sss.pgh.pa.us> <3BBE635F64E28D4C899377A61DAA9FE02E2F3B84@NBSVR-MAIL01.radiantblue.local> <27138.1402674700@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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