1.找到Postgresql安装目录/share/contrib
2.在目录中找到dblink.sql,执行这个文件里的SQL语句.
3.
与远程服务器建立一个连接:
select dblink_connect('db_name','dbname=db_name host=192.168.1.1 user=postgres password=123456');
通过这个连接访问那台数据库:
select * from dblink('db_name','SELECT id, name FROM test') as test(id integer, name character varying(50));
数据库内容:
CREATE TABLE test
(
id serial NOT NULL,
"name" character(50),
CONSTRAINT id PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
ALTER TABLE test OWNER TO postgres;