简体   繁体   中英

Copy Table data from one DB to another

For development I find myself needing to copy table information from one table to another quite often. I am just curious what are the easiest solutions to do this for Postgres. I have PGAdminIII but it looks like it really only support the long drawn out Backup/Restore.

Is there a python or bash script somewhere or something that I can just give it the basic infomation?

  • Here is DB1
  • Here is DB2
  • Copy Tables ...
  • Go!

I believe SQLYog did this for MySQL in Win32, but I am now on OSX and using Postgres.

Kettle, aka pentaho data integration can do this for you. http://sourceforge.net/projects/pentaho/files/Data%20Integration/

  1. Download kettle and unzip.
  2. Make sure you have a java runtime environment (1.5 and 1.6 will both work for the 3.2 stable version).
  3. Run spoon.sh
  4. Create a new job (file/new/job)
  5. Define source and target connections (click on the view button above the tree, dbl click on the database connections node to open the connection wizard or do menu/wizard/create db connection wizard)
  6. Do menu/wizard/copy tables wizard
  7. follow the wizard steps
  8. run job (play button on toolbar)

If you're just moving between two PostgreSQL databases, a good way is to just use pg_dump and pg_restore in a pipe (or pg_dump and psql). Basically

pg_dump -Fc db1 | pg_restore -d db2 -c

(adjust switches as necessary for your environment, see the man pages)

It's tools you have already installed, and if you just want to transfer the data and not modify it, it'll be a lot faster than a full-blown ETL too like Kettle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM