Re: Dumping a table from one database and adding it to another

Поиск
Список
Период
Сортировка
От Brent Wood
Тема Re: Dumping a table from one database and adding it to another
Дата
Msg-id 4CF8ED8B0200007B00033ED2@gwia.niwa.co.nz
обсуждение исходный текст
Список pgsql-general



Brent Wood
DBA/GIS consultant
NIWA, Wellington
New Zealand

>>> "James B. Byrne" <byrnejb@harte-lyne.ca> 12/03/10 12:56 PM >>>
I have read the documentation respecting backups but I cannot seem
to find any mention of the specific case that I wish performed.

Hi James,

pg_dump can take arguments to dump a specified table, the output can be filtered/edited in a pipe & passed back to psql accessing a different database on the same or another host:

You may need to set user & other parameters, but a quick example;

 to dump a table, rename it & recreate in a different db on another server on the fly:

pgdump -h <host1> -t <src table> <db1>  |   sed 's/src table/target table/g'   |   psql -h <host2> -d <db2>

<   dump named table in specified db    ><     change all occurences of     ><     run the SQL in the         >
                                                                  original table name to new one                target db


By piping through sed you can also change column names, just as this does the table name.

But note that if you have users/tables/columns with the same name, this is not going to be straightforward...


HTH,

  Brent Wood


I have a pair of tables in a production database that I wish to dump
and then restore to a new, different database. I can, and probably
will, recreate the tables and column layouts in the new database.

Is there a way to load the data dumped from a single table in one
database into a new, possibly differently named, table in a
different database, using PG utilities?


--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Please consider the environment before printing this email.

NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

В списке pgsql-general по дате отправления:

Предыдущее
От:
Дата:
Сообщение: Re: Looking for auto starting procedures
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Looking for auto starting procedures