Copy a table from one database to another in Postgres

前端 未结 19 1238
慢半拍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 00:49

    First install dblink

    Then, you would do something like:

    INSERT INTO t2 select * from 
    dblink('host=1.2.3.4
     user=*****
     password=******
     dbname=D1', 'select * t1') tt(
           id int,
      col_1 character varying,
      col_2 character varying,
      col_3 int,
      col_4 varchar 
    );
    

提交回复
热议问题