[英]How can I migrate data from one PostgreSQL database to another (with slightly different table/column names)?
I am trying to migrate a large portion of one postgres database to another postgres database that has a slightly different layout/table names/column names.我正在尝试将一个 postgres 数据库的大部分迁移到另一个布局/表名/列名略有不同的 postgres 数据库。 But the data is the same.
但是数据是一样的。 What is a good way to do this?
有什么好方法可以做到这一点? All I can think of is using pg_dump and then manually changing the column names and table names in the dump file but there is a lot of data to work through and that way would also be very error prone.
我能想到的只是使用 pg_dump,然后手动更改转储文件中的列名和表名,但是有很多数据需要处理,这样也很容易出错。
Use dblink to add data to new tables in the new database.使用 dblink 将数据添加到新数据库中的新表中。
Example:例子:
INSERT into new_table ( cd_ace, no_desc )
SELECT cd_accessory, no_description
FROM DBLINK('host=ip_address_remote port=5470 dbname=database_name user=user password=password ',
'SELECT cd_acessorio, no_description from dbatez.acessorio')
AS a ( cd_accessory character varying(4), no_description character varying(40));
I hope I helped you.我希望我对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.