Re: best method to copy data across databases

Lists: pgsql-sql
From: ctrl(at)altonsys(dot)com (ctrl)
To: pgsql-sql(at)postgresql(dot)org
Subject: best method to copy data across databases
Date: 2004-07-02 03:42:04
Message-ID: 46a31c4d.0407011942.37839bb0@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

I need to copy data that I have on a table in one Postgres database
into another table, on a different database. The destination table is
not identical with the source table so I need to do some mapping
between the 2 tables.
What would be the best (and quickest) way to transfer the data? (there
are over 500k rows)

thanks!


From: reina_ga(at)hotmail(dot)com (Tony Reina)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: best method to copy data across databases
Date: 2004-07-02 11:10:15
Message-ID: 272e4be7.0407020310.18785557@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

ctrl(at)altonsys(dot)com (ctrl) wrote in message news:<46a31c4d(dot)0407011942(dot)37839bb0(at)posting(dot)google(dot)com>...
> I need to copy data that I have on a table in one Postgres database
> into another table, on a different database. The destination table is
> not identical with the source table so I need to do some mapping
> between the 2 tables.
> What would be the best (and quickest) way to transfer the data? (there
> are over 500k rows)
>
> thanks!

If the 2 tables have different arrangements, then I'm not sure if
there is a quick way. The safest way is probably to do a pg_dump
--attribute-inserts.

From the pg_dump manpage,

--attribute-inserts

Dump data as INSERT commands with explicit column names
(INSERT
INTO table (column, ...) VALUES ...). This will make
restoration
very slow, but it is necessary if you desire to
rearrange the
column ordering.

HTH,
-Tony


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: reina_ga(at)hotmail(dot)com (Tony Reina)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: best method to copy data across databases
Date: 2004-07-02 14:12:07
Message-ID: 14059.1088777527@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

reina_ga(at)hotmail(dot)com (Tony Reina) writes:
> If the 2 tables have different arrangements, then I'm not sure if
> there is a quick way. The safest way is probably to do a pg_dump
> --attribute-inserts.

In recent versions (definitely 7.4, don't remember about 7.3),
pg_dump will include a column list in its COPY commands, so a
plain pg_dump should work. The way with COPY will be a good bit
faster than a pile of INSERT commands.

regards, tom lane


From: ctrl(at)altonsys(dot)com (ctrl)
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: best method to copy data across databases
Date: 2004-07-03 18:19:50
Message-ID: 46a31c4d.0407031019.78b04fdb@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Many thanks Tony and Tom,

since this was a "one time" process speed wasn't an issue...
I just did a plain pg_dump with insert and explicit column names in
the dump, then used vi to rename the columns and get rid of some of
them...
non very scientific but it worked :)

cheers.

tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane) wrote in message news:<14059(dot)1088777527(at)sss(dot)pgh(dot)pa(dot)us>...
> reina_ga(at)hotmail(dot)com (Tony Reina) writes:
> > If the 2 tables have different arrangements, then I'm not sure if
> > there is a quick way. The safest way is probably to do a pg_dump
> > --attribute-inserts.
>
> In recent versions (definitely 7.4, don't remember about 7.3),
> pg_dump will include a column list in its COPY commands, so a
> plain pg_dump should work. The way with COPY will be a good bit
> faster than a pile of INSERT commands.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match