Kliver Max Kliver Max - 1 year ago 44
SQL Question

How to copy table from server to another in PostgreSQL?

I have two servers on PostgreSQL 8.4:


Now i want to copy table from server1 and put it in data base on server2.

Its possible to do?


I try do like in @Valery Viktorovsky's answer:

pg_dump --server1:5432 --encoding=utf8 --no-owner --username=postgres --123456 np_point > D:\np_point.sql
psql --server2:5432 --username=postgres mrsk -f D:\np_point.sql

and get error:

ERROR: syntax error at or near "pg_dump"
LINE 1: pg_dump --server1:5432 --encoding=utf8 --no-owner --use...

Answer Source

The safest way is to use pg_dump.

1. pg_dump --host server1 --encoding=utf8 --no-owner --username=foo --password -t table_name db_name > server1_db.sql
2. psql --host server2 --username=foo db_name -f server1_db.sql