Re: Backing Up Partial Databases

From: Shane Ambler <pgsql(at)007Marketing(dot)com>
To: Duncan McDonald <duncan(at)gpats(dot)com(dot)au>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Backing Up Partial Databases
Date: 2006-10-26 06:38:05
Message-ID: 454057CD.5030401@007Marketing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Duncan McDonald wrote:
> Hi All,
>
> I was wondering whether there was a way to back up partial sets of data
> as INSERT statements? Pg_dump seems only to handle whole databases or
> tables.
>
> I have two identical databases (primary and backup) and I need to
> transfer a small portion of missing data from one to the other. Is there
> an easier way to do this rather than SELECT-ing the interval then
> parsing the ouput to look like INSERT statements?
>

I can think of a couple of ways -

COPY (SELECT * FROM myPrimaryTable WHERE id<200) TO '/tmp/myData';

you can then

COPY myBackupTable FROM '/tmp/myData';

Another option is to create a table to hold the selected rows then
SELECT * INTO myTempTable FROM myPrimaryTable WHERE id<200;

then use pg_dump --table=myTempTable > /tmp/myData

the --inserts option of pg_dump will export as INSERT's if that is the
way you want to do it. You will need to do a find and replace on the
INSERT's to change the table name though.

--

Shane Ambler
pgSQL(at)007Marketing(dot)com

Get Sheeky @ http://Sheeky.Biz

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Andrew Sullivan 2006-10-26 11:03:09 Re: Vacuum Problems (locking)
Previous Message Duncan McDonald 2006-10-26 03:08:42 Backing Up Partial Databases