Copy a table from one database to another in Postgres

前端 未结 19 1295
慢半拍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:50

    Extract the table and pipe it directly to the target database:

    pg_dump -t table_to_copy source_db | psql target_db
    

    Note: If the other database already has the table set up, you should use the -a flag to import data only, else you may see weird errors like "Out of memory":

    pg_dump -a -t my_table my_db | psql target_db
    

提交回复
热议问题