Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 23440632A45 for ; Thu, 8 Apr 2010 13:55:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 58818-07 for ; Thu, 8 Apr 2010 16:55:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 62FF1632186 for ; Thu, 8 Apr 2010 13:55:43 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Thu, 08 Apr 2010 11:55:42 -0500 Message-Id: <4BBDC43802000025000305A9@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Thu, 08 Apr 2010 11:55:36 -0500 From: "Kevin Grittner" To: "Renato Oliveira" , "pgsql-admin" Subject: Re: Restore data to an existing populated table References: <7965A9DCF12CC14984420BCC37B1608F25ABF311FB@Elzar.grant.co.uk> In-Reply-To: <7965A9DCF12CC14984420BCC37B1608F25ABF311FB@Elzar.grant.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.185 tagged_above=-10 required=5 tests=BAYES_40=-0.185 X-Spam-Level: X-Archive-Number: 201004/91 X-Sequence-Number: 34185 Renato Oliveira wrote: > I would like to know if it is possible to restore data to a > pre-populated db/table. Yes. > Does that mean the table can exist and can be populated with > data, pg_restore will append the data to the db/table without > deleting/dropping the existing data? Unless you explicitly use the "clean" option, yes. > What I need to achieve is: > 1 - Download the schema from an old DB pg_dump -s > 2 - Restore the schema to a new DB psql or pg_restore (depending on dump format) > 3 - Point my application to the new DB, it will populate with new > data > 4 - at later date do a pg_dump to dump the data from old DB - > (Should I use 'COPY' statement instead of pg_dump? pg_dump -a (It will use COPY statements.) > 5 - Restore the data only to the new DB - as in copying the data > and appending it to existing db/tables. psql or pg_restore (depending on dump format) (You'll have problems if there are duplicates on primary key or unique indexes or constraints.) > What is the natural behaviour of pg_restore, does it wipe the > existing data on the existing DB, or it displays 'errors' and > carries on copying the data? It never destroys data unless you explicitly tell it to do so. If it hits and error attempting to add data to a table (due to schema mismatch or duplicate rows, for example) the entire copy in to the table fails. I hope this helps. -Kevin