简体   繁体   English

PostgreSQL:如何将数据从一个数据库表复制到另一个数据库

[英]PostgreSQL: How to copy data from one database table to another database

I need simple example how to copy data from database DB1 table T1 to database DB2 table T2 . 我需要简单的示例如何将数据从数据库DB1T1复制到数据库DB2T2

T2 has identical structure like T1 (same column names, properties. Just different data) DB2 running on same server like DB1, but on different port. T2具有与T1相同的结构(相同的列名,属性。只是不同的数据)DB2在同一服务器上运行,如DB1,但在不同的端口上。

In the case the two databases are on two different server instances, you could export in CSV from db1 and then import the data in db2 : 如果两个数据库位于两个不同的服务器实例上,则可以从db1导出CSV,然后在db2导入数据:

COPY (SELECT * FROM t1) TO '/home/export.csv';

and then load back into db2 : 然后加载回db2

COPY t2 FROM '/home/export.csv';

Again, the two tables on the two different database instances must have the same structure. 同样,两个不同数据库实例上的两个表必须具有相同的结构。

Using the command line tools : pg_dump and psql , you could do even in this way : 使用命令行工具:pg_dump和psql,你甚至可以这样做:

pg_dump -U postgres -t t1 db1 | psql -U postgres -d db2

You can specify command line arguments to both pg_dump and psql to specify the address and/or port of the server . 您可以为pg_dumppsql指定命令行参数,以指定服务器的地址和/或端口。

Another option would be to use an external tool like : openDBcopy , to perform the migration/copy of the table. 另一种选择是使用外部工具,如: openDBcopy ,来执行表的迁移/复制。

你可以尝试这个 -

 pg_dump -t table_name_to_copy source_db | psql target_db

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在postgresql中将数据从一个数据库复制到另一个数据库? - how to copy data from one database to another database in postgresql? 如何将数据从一个数据库表复制到另一数据库表? - How to copy data from one database table to another database table? 将数据从一个数据库中的表复制到另一个数据库 - Copy Data from a table in one Database to another database 如何将带有数据的表列从一个数据库复制到另一个数据库? - How I can copy a table columns with data from one database to another database? 如何将数据从一个 PostgreSQL 数据库迁移到另一个(表/列名略有不同)? - How can I migrate data from one PostgreSQL database to another (with slightly different table/column names)? 我可以将数据从一个数据库表复制到另一个已经存在的数据库表sql服务器吗? - Can i copy data from one database table to another already existing database table sql server? 使用Java将数据从一个oracle数据库表复制到另一数据库表 - Using Java Copy data from one oracle Database table to another database table Django:将数据从一个数据库复制到另一个数据库 - Django: copy data from one database to another 如何将数据从一个数据库复制到另一个数据库? - How copy data from one database to another on different server? 如何在 Google Cloud 中将数据从一个数据库复制到另一个数据库 - How to copy data from one database to another in Google Cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM