首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Postgres中将表从一个数据库复制到另一个数据库

在Postgres中将表从一个数据库复制到另一个数据库
EN

Stack Overflow用户
提问于 2010-07-07 21:27:59
回答 13查看 295.2K关注 0票数 333

我正尝试在Postgres中将整个表从一个数据库复制到另一个数据库。有什么建议吗?

EN

回答 13

Stack Overflow用户

发布于 2010-07-08 09:45:18

使用dblink会更方便!

代码语言:javascript
复制
truncate table tableA;

insert into tableA
select *
from dblink('hostaddr=xxx.xxx.xxx.xxx dbname=mydb user=postgres',
            'select a,b from tableA')
       as t1(a text,b text);
票数 91
EN

Stack Overflow用户

发布于 2013-10-31 09:54:35

在与两台服务器都有连接的linux主机上使用psql

代码语言:javascript
复制
( 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" )
票数 39
EN

Stack Overflow用户

发布于 2015-04-15 17:41:42

第一个install dblink

然后,您将执行如下操作:

代码语言:javascript
复制
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 
);
票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3195125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档