Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WvTlb-0006ae-9I for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Jun 2014 15:51:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WvTlZ-0006io-NW for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Jun 2014 15:51:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WvTlY-0006iT-Ld for pgsql-bugs@postgresql.org; Fri, 13 Jun 2014 15:51:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WvTlV-0003J0-MJ for pgsql-bugs@postgresql.org; Fri, 13 Jun 2014 15:51:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s5DFpeAW027139; Fri, 13 Jun 2014 11:51:40 -0400 From: Tom Lane To: "Burgess, Freddie" cc: "pgsql-bugs@postgresql.org" Subject: Re: pg_restore PostgreSQL 9.3.3 problems 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> Comments: In-reply-to "Burgess, Freddie" message dated "Fri, 13 Jun 2014 15:34:30 -0000" Date: Fri, 13 Jun 2014 11:51:40 -0400 Message-ID: <27138.1402674700@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "Burgess, Freddie" 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