Re: Shell script to extract a table from a plain text dump

Lists: pgsql-generalpgsql-hackers
From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Shell script to extract a table from a plain text dump
Date: 2005-10-07 08:46:12
Message-ID: 434635D4.7000604@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

If you have huge plain text dumps, and just want to restore one table
it's usually painful. Attached is a small shell script that can take a
plain text dump and extract a single table's COPY data commands from it.

If people think it's interesting and should be developed, I can pop it
on pgfoundry or something.

Chris

Attachment Content-Type Size
restore.sh text/plain 1.1 KB

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Shell script to extract a table from a plain text dump
Date: 2005-10-07 09:36:27
Message-ID: 20051007093622.GA11321@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

On Fri, Oct 07, 2005 at 04:46:12PM +0800, Christopher Kings-Lynne wrote:
> If you have huge plain text dumps, and just want to restore one table
> it's usually painful. Attached is a small shell script that can take a
> plain text dump and extract a single table's COPY data commands from it.
>
> If people think it's interesting and should be developed, I can pop it
> on pgfoundry or something.

Hmm, what I usually use is:

bzcat $file | sed -ne "/^COPY \"$table\" /,/^\\\.\$/p"

However, error checking and wrapping it into a script is a good idea.
If it got given a couple of switches to control the output, maybe we
can have a pg_restore for text dumps :)

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] Shell script to extract a table from a plain text dump
Date: 2005-10-07 14:17:21
Message-ID: 20051007141721.GD5175@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

On Fri, Oct 07, 2005 at 11:36:27AM +0200, Martijn van Oosterhout wrote:
> On Fri, Oct 07, 2005 at 04:46:12PM +0800, Christopher Kings-Lynne wrote:
> > If you have huge plain text dumps, and just want to restore one table
> > it's usually painful. Attached is a small shell script that can take a
> > plain text dump and extract a single table's COPY data commands from it.
> >
> > If people think it's interesting and should be developed, I can pop it
> > on pgfoundry or something.
>
> Hmm, what I usually use is:
>
> bzcat $file | sed -ne "/^COPY \"$table\" /,/^\\\.\$/p"
>
> However, error checking and wrapping it into a script is a good idea.
> If it got given a couple of switches to control the output, maybe we
> can have a pg_restore for text dumps :)

If only the text dump could have a TOC, by means of which it would be
possible to seek to the exact position of the dump that has a table's
dump, it would certainly be useful. Otherwise, you need to read the
whole file anyway, which is bad. Of course, if it's compressed then
there's not much you can do.

--
Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4
"Los dioses no protegen a los insensatos. Éstos reciben protección de
otros insensatos mejor dotados" (Luis Wu, Mundo Anillo)


From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Shell script to extract a table from a plain text dump
Date: 2005-10-08 07:52:52
Message-ID: 43477AD4.9000905@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

Argh! That's some sed coolness :)

Chris

Martijn van Oosterhout wrote:
> On Fri, Oct 07, 2005 at 04:46:12PM +0800, Christopher Kings-Lynne wrote:
>
>>If you have huge plain text dumps, and just want to restore one table
>>it's usually painful. Attached is a small shell script that can take a
>>plain text dump and extract a single table's COPY data commands from it.
>>
>>If people think it's interesting and should be developed, I can pop it
>>on pgfoundry or something.
>
>
> Hmm, what I usually use is:
>
> bzcat $file | sed -ne "/^COPY \"$table\" /,/^\\\.\$/p"
>
> However, error checking and wrapping it into a script is a good idea.
> If it got given a couple of switches to control the output, maybe we
> can have a pg_restore for text dumps :)
>
> Have a nice day,