Copy a table from one database to another in Postgres

前端 未结 19 1237
慢半拍i
慢半拍i 2020-11-28 00:21

I am trying to copy an entire table from one database to another in Postgres. Any suggestions?

19条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 01:00

    Using psql, on linux host that have connectivity to both servers

    ( export PGPASSWORD=password1 
      psql -U user1 -h host1 database1 \
      -c "copy (select field1,field2 from table1) to stdout with csv" ) \
    | 
    ( export PGPASSWORD=password2 
      psql -U user2 -h host2 database2 \ 
       -c "copy table2 (field1, field2) from stdin csv" )
    

提交回复
热议问题