colorful

zc qq:1337220912

 

Postgresql跨数据库查询

postgres 跨数据库查询

dblink 的安装
   linux
      #cd postgres源码安装目录/contrib/dblink
      # make
      # make install
      注意: 如果你在安装了postgres后执行了 make clean, make distclean, 那你可能需要重新 ./configure make make install 一下
   windows
      windows 默认是安装的

dblink模块加载
   PostgreSQL 有很多外部模块可以加载,例如 dblink, pg_buffercache 等,在 9.1 版本
   以前,只要对应的 postgresql-contrib 已经安装,只需要将对应的 sql 文件导入到目标库
   即可,例如,要在 数据库 skytf 里安装 dblink 模块,只需要执行以下操作就行;

   cd $PGHOME/share/contrib
   psql -d skytf -U postgresql -f dblink.sql
   导入成功之后,那么 dblink 模块即加载成功。
   
   注意!!
   在 9.1 版本以后,模块加载环节 PostgreSQL 提供命令 "CREATE EXTENSION" 来替代以上操作。  
   通过执行 CREATE EXTENSION dblink来加载 dblink

dblink 使用:
   关于dblink, dblink_connect, dblink_disconnect 请参考手册
   http://www.postgresql.org/docs/9.1/static/dblink.html
   例1
   select dblink_connect('连接名','host=192.168.1.27  port=1921 dbname=testdb user=test_user password=test_user' );
   host, port, user等 可以跟据情况省略掉

   例2
   select * from tb1 inner join dblink('dbname=db2', 'select id from tb2 where id=\'20120623\'') as acc(id int) on tb1.id = acc.id order by tb1.id;

参考网站:
http://blog.sina.com.cn/s/blog_538d55be01010clc.html
http://francs3.blog.163.com/blog/static/4057672720108401139868/
http://www.postgresql.org/docs/9.1/static/dblink.html
http://zhenghaoju700.blog.163.com/blog/static/135859518201251382628663/

posted on 2013-07-14 16:46 多彩人生 阅读(1297) 评论(0)  编辑 收藏 引用 所属分类: postgresql


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜