将表从localhost复制到远程服务器?

时间:2015-07-22 10:08:58

标签: postgresql postgresql-9.3

我使用以下代码将表从远程数据库复制到本地

INSERT INTO manifest_status select * from 
dblink('host=1.2.3.4
 user=bn_openerp
 password=12345678
 dbname=Bodywears', 'select * FROM manifest_status') t1(
       id int,
  manifest_no character varying,
  tracking_number character varying,
  order_number character varying,
  status character varying,
  pos character varying
 );

工作正常,

我的应用程序更改本地存储的表中的数据。

现在我想在host = 1.2.3.4上的远程服务器上传表

3 个答案:

答案 0 :(得分:0)

我认为有两种情况:

第一种情况:远程服务器上没有活动。我的意思是你的远程服务器没有更新/插入/删除" manifest_status"表。 如果是这样,您可以删除远程服务器上的该表,然后从本地复制到您的服务器。请不要忘记备份该平板电脑。

第二种情况:该表已更新/插入/删除。我认为你必须手动进行迁移。这意味着您必须比较本地和远程数据之间的差异。

答案 1 :(得分:0)

createdb -U postgres -h 1.2.3.4 restored_mydb
pg_dump -U postgres mydb | ssh 1.2.3.4 "psql -d restored_mydb -U postgres"

答案 2 :(得分:-1)

您应该通过CSV格式文件导出本地数据。

请使用此命令:

COPY manifest_status TO '/tmp/manifest_status.csv' DELIMITER ',' CSV HEADER;

请阅读@ http://www.postgresql.org/docs/current/static/sql-copy.html

中的Postgres手册
相关问题