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?
2 Answers
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.
1 Comment
BillRobertson42
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.
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