How to copy a table from a server to another in PostgreSQL?

I have two servers on PostgreSQL 8.4:

server1:5432
server2:5432

Now I want to copy the table from server1 and put it in the database on server2.
Can it be done?

UPDATE

I try to make @Valery Viktorovsky 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 the error:

 ERROR:  syntax error at or near "pg_dump"
LINE 1: pg_dump --server1:5432 --encoding=utf8 --no-owner --use...
+5
source share
4 answers

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
+9
source

try it

using the COPY command from psql. Connect to server1 and export to CSV , then connect to server2 and import from CSV

+4
source

 pg_dump -h localhost -U postgres -p 5432 -C -t table_name source_db_name | ssh -C username@ip "psql -h localhost -U postgres -p 5432 destination_db_name"
+1

You can also use the Linux script shell to transfer table data from one server to another PostgreSQL server.

I just posted my answer below a similar stack question, please refer to this. Copying a PostgreSQL database to another server

+1
source

All Articles