我正尝试在Postgres中将整个表从一个数据库复制到另一个数据库。有什么建议吗?
发布于 2010-07-08 09:45:18
使用dblink会更方便!
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);
发布于 2013-10-31 09:54:35
在与两台服务器都有连接的linux主机上使用psql
( 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" )
发布于 2015-04-15 17:41:42
然后,您将执行如下操作:
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
);
https://stackoverflow.com/questions/3195125
复制相似问题