10

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,043
  • 2
  • 14
  • 33

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,243
  • 2
  • 31
  • 56
  • 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. – BillRobertson42 Feb 13 '15 at 15:08
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
  • 7,103
  • 3
  • 45
  • 43