9

What would be the best way to copy data from one table, one database, one server to the table in another database, another server in PostgreSQL?

Nash
  • 1,003
  • 2
  • 13
  • 32

2 Answers2

12

pg_dump allows the dumping of only select tables:

pg_dump -Fc -f output.dump -t tablename databasename

(dump 'tablename' from database 'databasename' into file 'output.dump' in pg_dumps binary custom format)

You can restore that dump on your other server with pg_restore:

pg_restore -d databasename output.dump

If the table itself already exists in your target database, you can import only the rows by adding the --data-only flag.

janfoeh
  • 10,235
  • 2
  • 30
  • 55
  • 2
    If you're using pgadmin3, you can run pg_dump/pg_restore by right clicking on a database or table and choosing the backup/restore menu items. It's OK for simple one off tasks. – Bill Feb 13 '15 at 15:08
  • Thanks for your answer. – Nash Feb 13 '15 at 16:19
0

I shared a shell to copy table from one server to another PostgreSQL server. Please refer this another stack question. Copying PostgreSQL database to another server

Community
  • 1
  • 1
Anvesh
  • 6,210
  • 3
  • 43
  • 42