Обсуждение: Truncate on pg_dump / pg_restore

Поиск
Список
Период
Сортировка

Truncate on pg_dump / pg_restore

От
Bryce Nesbitt
Дата:
Dear Postgres Gurus;

Is there a way to truncate a table, at pg_dump time?

I'm aware of various ways to exclude a table from a dump (>= 8.2), or to
selectively pg_restore.  What I'm seeking here is different.  I've got
tables with pretty disposable data... meaning I want to drop the data...
but restore empty indexed tables at pg_restore time.

Doable?


Re: Truncate on pg_dump / pg_restore

От
"chris smith"
Дата:
On Sat, Oct 25, 2008 at 5:32 PM, Bryce Nesbitt <bryce2@obviously.com> wrote:
> Dear Postgres Gurus;
>
> Is there a way to truncate a table, at pg_dump time?
>
> I'm aware of various ways to exclude a table from a dump (>= 8.2), or to
> selectively pg_restore.  What I'm seeking here is different.  I've got
> tables with pretty disposable data... meaning I want to drop the data...
> but restore empty indexed tables at pg_restore time.

Do a schema-only dump.

pg_dump --help says use '-s' or '--schema-only'.

-- 
Postgresql & php tutorials
http://www.designmagick.com/


Re: Truncate on pg_dump / pg_restore

От
Bryce Nesbitt
Дата:
<br /><br /> chris smith wrote: <blockquote cite="mid:3c1395330810250318r6f4c7e1ao9eac8dd35eed2726@mail.gmail.com"
type="cite"><prewrap="">On Sat, Oct 25, 2008 at 5:32 PM, Bryce Nesbitt <a class="moz-txt-link-rfc2396E"
href="mailto:bryce2@obviously.com"><bryce2@obviously.com></a>wrote: </pre><blockquote type="cite"><pre
wrap="">I'vegot
 
tables with pretty disposable data... meaning I want to drop the data...
but restore empty indexed tables at pg_restore time.   </pre></blockquote><pre wrap="">
Do a schema-only dump.
pg_dump --help says use '-s' or '--schema-only'. </pre></blockquote> Ooops, I was unclear.  I want most of the data! 
Thereare just a few tables that I'd prefer be empty (truncated) in the restored database.  Most of the tables (and
thereare lots) are valuable.<br /><br /> Could I  dump --schema-only, dump full, dump the toc, comment out the tables
fromthe toc, restore the --schema-only, then restore the dump (minus the contents of the unwanted tables)?<br /><br /> 

Re: Truncate on pg_dump / pg_restore

От
"Harold A. Giménez Ch."
Дата:
You can, assuming you start off with a pg_dump in custom format (use -Fc). You can use pg_restore's -l option to drop
outthe list contents of the archive, and then comment out whatever you do not want restored:<br /><br /><br />pg_dump
-Fc....... > your_db.dump<br /><br />pg_restore -l your_db.dump > your_db.list<br /><br /># edit your_db.list and
commentout whatever you don't need (or reorder if needed)<br /><br /># use your_db.list for the actual restore:<br
/><br/>pg_restore -L your_db.list your_db.dump<br /><strong class="userinput"><code></code></strong><br /><br />Look at
theexamples on:<br /><br /><a
href="http://www.postgresql.org/docs/8.3/interactive/app-pgrestore.html">http://www.postgresql.org/docs/8.3/interactive/app-pgrestore.html</a><br
/><br/><div class="gmail_quote">On Sat, Oct 25, 2008 at 11:23 AM, Bryce Nesbitt <span dir="ltr"><<a
href="mailto:bryce2@obviously.com">bryce2@obviously.com</a>></span>wrote:<br /><blockquote class="gmail_quote"
style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div bgcolor="#ffffff"
text="#000000"><br/><br /> chris smith wrote: <blockquote type="cite"><pre>On Sat, Oct 25, 2008 at 5:32 PM, Bryce
Nesbitt<a href="mailto:bryce2@obviously.com" target="_blank"><bryce2@obviously.com></a> wrote: </pre><blockquote
type="cite"><pre>I'vegot
 
tables with pretty disposable data... meaning I want to drop the data...
but restore empty indexed tables at pg_restore time.   </pre></blockquote><pre>Do a schema-only dump.
pg_dump --help says use '-s' or '--schema-only'. </pre></blockquote> Ooops, I was unclear.  I want most of the data! 
Thereare just a few tables that I'd prefer be empty (truncated) in the restored database.  Most of the tables (and
thereare lots) are valuable.<br /><br /> Could I  dump --schema-only, dump full, dump the toc, comment out the tables
fromthe toc, restore the --schema-only, then restore the dump (minus the contents of the unwanted tables)?<br /><br
/></div></blockquote></div><br/>