postgres外部表之-oracle_fdw
1. 安装Oracle客户端工具
编译安装oracle_fdw之前,需要安装Oracle的客户端程序;步骤略
下载地址:http://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html
2. 安装oracle_fdw
下载地址:http://pgxn.org/dist/oracle_fdw/
[root@Postgres201 opt]# unzip oracle_fdw-2.0.0.zip
[root@Postgres201 opt]# cd oracle_fdw-2.0.0
#加载环境变量后执行 pg_config是否在对应PGHOME/bin目录下。编译后会在对应的目录下面
[root@Postgres201 oracle_fdw-2.0.0]# source /home/postgres/.bashrc
[root@Postgres201 oracle_fdw-2.0.0]# pg_config
[root@Postgres201 oracle_fdw-2.0.0]# make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I/u01/app/oracle/sdk/include -I/u01/app/oracle/oci/include -I/u01/app/oracle/rdbms/public -I/usr/include/oracle/12.2/client -I/usr/include/oracle/12.2/client64 -I/usr/include/oracle/12.1/client -I/usr/include/oracle/12.1/client64 -I/usr/include/oracle/11.2/client -I/usr/include/oracle/11.2/client64 -I/usr/include/oracle/11.1/client -I/usr/include/oracle/11.1/client64 -I/usr/include/oracle/10.2.0.5/client -I/usr/include/oracle/10.2.0.5/client64 -I/usr/include/oracle/10.2.0.4/client -I/usr/include/oracle/10.2.0.4/client64 -I/usr/include/oracle/10.2.0.3/client -I/usr/include/oracle/10.2.0.3/client64 -I. -I./ -I/opt/pgsql96/include/server -I/opt/pgsql96/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o oracle_fdw.o oracle_fdw.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I/u01/app/oracle/sdk/include -I/u01/app/oracle/oci/include -I/u01/app/oracle/rdbms/public -I/usr/include/oracle/12.2/client -I/usr/include/oracle/12.2/client64 -I/usr/include/oracle/12.1/client -I/usr/include/oracle/12.1/client64 -I/usr/include/oracle/11.2/client -I/usr/include/oracle/11.2/client64 -I/usr/include/oracle/11.1/client -I/usr/include/oracle/11.1/client64 -I/usr/include/oracle/10.2.0.5/client -I/usr/include/oracle/10.2.0.5/client64 -I/usr/include/oracle/10.2.0.4/client -I/usr/include/oracle/10.2.0.4/client64 -I/usr/include/oracle/10.2.0.3/client -I/usr/include/oracle/10.2.0.3/client64 -I. -I./ -I/opt/pgsql96/include/server -I/opt/pgsql96/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o oracle_utils.o oracle_utils.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I/u01/app/oracle/sdk/include -I/u01/app/oracle/oci/include -I/u01/app/oracle/rdbms/public -I/usr/include/oracle/12.2/client -I/usr/include/oracle/12.2/client64 -I/usr/include/oracle/12.1/client -I/usr/include/oracle/12.1/client64 -I/usr/include/oracle/11.2/client -I/usr/include/oracle/11.2/client64 -I/usr/include/oracle/11.1/client -I/usr/include/oracle/11.1/client64 -I/usr/include/oracle/10.2.0.5/client -I/usr/include/oracle/10.2.0.5/client64 -I/usr/include/oracle/10.2.0.4/client -I/usr/include/oracle/10.2.0.4/client64 -I/usr/include/oracle/10.2.0.3/client -I/usr/include/oracle/10.2.0.3/client64 -I. -I./ -I/opt/pgsql96/include/server -I/opt/pgsql96/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o oracle_gis.o oracle_gis.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -shared -o oracle_fdw.so oracle_fdw.o oracle_utils.o oracle_gis.o -L/opt/pgsql96/lib -Wl,--as-needed -Wl,-rpath,'/opt/pgsql96/lib',--enable-new-dtags -L/u01/app/oracle -L/u01/app/oracle/bin -L/u01/app/oracle/lib -lclntsh -L/usr/lib/oracle/12.2/client/lib -L/usr/lib/oracle/12.2/client64/lib -L/usr/lib/oracle/12.1/client/lib -L/usr/lib/oracle/12.1/client64/lib -L/usr/lib/oracle/11.2/client/lib -L/usr/lib/oracle/11.2/client64/lib -L/usr/lib/oracle/11.1/client/lib -L/usr/lib/oracle/11.1/client64/lib -L/usr/lib/oracle/10.2.0.5/client/lib -L/usr/lib/oracle/10.2.0.5/client64/lib -L/usr/lib/oracle/10.2.0.4/client/lib -L/usr/lib/oracle/10.2.0.4/client64/lib -L/usr/lib/oracle/10.2.0.3/client/lib -L/usr/lib/oracle/10.2.0.3/client64/lib
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [oracle_fdw.so] Error 1
FAQ:执行make若出现“/usr/bin/ld: cannot find -lclntsh”;原因是找不到库liblclntsh文件;
解决方案:
1. 检查环境变量,看ORACLE有关的环境变量是否设置正确
2. 是否文件名字后有oracle版本信息;需要改名字
该文件在oracle安装目录下;本例是需要改名字即可
[root@Postgres201 oracle]# ln -sv libclntsh.so.11.1 libclntsh.so
[root@Postgres201 oracle_fdw-2.0.0]# make
[root@Postgres201 oracle_fdw-2.0.0]# make install
/bin/mkdir -p '/opt/pgsql96/lib'
/bin/mkdir -p '/opt/pgsql96/share/extension'
/bin/mkdir -p '/opt/pgsql96/share/extension'
/bin/mkdir -p '/opt/pgsql96/share/doc/extension'
/usr/bin/install -c -m 755 oracle_fdw.so '/opt/pgsql96/lib/oracle_fdw.so'
/usr/bin/install -c -m 644 .//oracle_fdw.control '/opt/pgsql96/share/extension/'
/usr/bin/install -c -m 644 .//oracle_fdw--1.1.sql .//oracle_fdw--1.0--1.1.sql '/opt/pgsql96/share/extension/'
/usr/bin/install -c -m 644 .//README.oracle_fdw '/opt/pgsql96/share/doc/extension/'
[root@Postgres201 oracle_fdw-2.0.0]# ll /opt/pgsql96/lib/oracle_fdw.so
-rwxr-xr-x. 1 root root 156608 May 29 23:15 /opt/pgsql96/lib/oracle_fdw.so
安装完成!
3. 创建oracle_fdw外部表
本例oracle服务器是在192.168.1.221上;oracle_fdw是通过oci接口访问Oracle了,所以需要配置$ORACLE_HOME/network/admin/tnsnames.ora。
[root@Postgres201 admin]# vi tnsnames.ora
ora221 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.221)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
3.1 创建oracle_fdw
lottu=# create extension oracle_fdw;
CREATE EXTENSION
查看以加载扩展模块
lottu=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+-----------------------------------------------------------
oracle_fdw | 1.1 | lottu | foreign data wrapper for Oracle access
pg_stat_statements | 1.4 | public | track execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgres_fdw | 1.0 | public | foreign-data wrapper for remote PostgreSQL servers
lottu=# select * from pg_foreign_data_wrapper ;
fdwname | fdwowner | fdwhandler | fdwvalidator | fdwacl | fdwoptions
--------------+----------+------------+--------------+--------+------------
postgres_fdw | 10 | 41021 | 41022 | |
oracle_fdw | 16384 | 49212 | 49213 | |
(2 rows)
3.2 在本地库创建SERVER
#采用//IP|解析主机名/实例名
CREATE SERVER oradb FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver '//oracle221/orcl');
#采用解析tnsnames.ora文件获取服务名
CREATE SERVER oradb FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver 'ora221');
lottu=# CREATE SERVER oradb FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver 'ora221');
CREATE SERVER
lottu=# GRANT USAGE ON FOREIGN SERVER oradb TO lottu;
GRANT
查看信息
lottu=# select * from pg_foreign_server where srvname = 'oradb';
srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions
---------+----------+--------+---------+------------+-----------------+-------------------
oradb | 16384 | 49216 | | | {lottu=U/lottu} | {dbserver=ora221}
lottu=# \des
List of foreign servers
Name | Owner | Foreign-data wrapper
-------+-------+----------------------
lottu | lottu | postgres_fdw
oradb | lottu | oracle_fdw
3.3 在本地库创建user mapping
lottu=# CREATE USER MAPPING FOR lottu SERVER oradb OPTIONS (user 'lottu', password 'li0924');
CREATE USER MAPPING
查看信息
lottu=# select * from pg_user_mappings where srvname = 'oradb';
umid | srvid | srvname | umuser | usename | umoptions
-------+-------+---------+--------+---------+------------------------------
49218 | 49217 | oradb | 16384 | lottu | {user=lottu,password=li0924}
lottu=# \deu
List of user mappings
Server | User name
--------+-----------
lottu | lottu
oradb | lottu
3.4 创建foreign table
在oracle中有表oratab
SQL> conn lottu/li0924
Connected.
SQL> desc oratab
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER
TEXT VARCHAR2(30)
创建外部表
lottu=# CREATE FOREIGN TABLE pgtab(id int OPTIONS(key 'true'), text varchar(30)) server oradb OPTIONS (schema 'LOTTU', table 'ORATAB');
查看信息
lottu=# select * from pg_foreign_table;
ftrelid | ftserver | ftoptions
---------+----------+------------------------------------------
41032 | 41027 | {schema_name=lottu,table_name=user_info}
49225 | 49217 | {schema=LOTTU,table=ORATAB}
(2 rows) lottu=# \det
List of foreign tables
Schema | Table | Server
--------+-----------+--------
lottu | pgtab | oradb
lottu | user_info | lottu
(2 rows)
注意点
1. CREATE FOREIGN TABLE中声明的列数据类型和其他性质必须要匹配实际的远程表。列名也必须匹配,
2. 原因是出现在OPTIONS (schema '×××', table '×××');里面的schema/table需要用大写标注
3. 在postgres9.3版本以后oracle_fdw支持对外部表的 Insert ,delete ,update ;增加表操作项 options(key 'true') (当值设置为 true|on|yes 表示不可以做增删改操作)
postgres外部表之-oracle_fdw的更多相关文章
- postgres外部表如何修改源码适配pg升级
postgres中外部表的应用如下: 但是许多在github上的fdw开源代码都是基于9.3以及9.4版本开发,原作者没有随着pg的版本升级而将外部表扩展升级,那只能靠自己去手动修改源码来让这些扩展能 ...
- postgres外部表
在创建外部表的时候遇见: CREATE EXTENSION file_fdw;2018-12-21 17:32:23.822 CST [31237] ERROR: could not open ex ...
- PG TO Oracle 增量同步-外部表
背景 最近在负责公司数据Oracle转PG:老平台数据库:Oracle11g:新平台数据库:PostgreSQL12.由于平台统计规则有变动:所以正在推广的游戏数据无法全部迁移过来:只能在老平台上运行 ...
- PostgreSQL中使用外部表
1. 安装file_fdw 需要先安装file_fdw,一般是进到PostgreSQL的源码包中的contrib/file_fdw目录下,执行: make make install 然后进入数据库中, ...
- GreenPlum 大数据平台--外部表(三)
一,外部表介绍 Greenplum 在数据加载上有一个明显的优势,就是支持数据的并发加载,gpfdisk是并发加载的工具,数据库中对应的就是外部表 所谓外部表,就是在数据库中只有表定义.没有数据,数据 ...
- Greenplum table 之 外部表
转载自: https://www.cnblogs.com/kingle-study/p/10552097.html 一.外部表介绍 Greenplum 在数据加载上有一个明显的优势,就是支持数据的并发 ...
- Oracle数据加载之外部表的介绍
环境: 服务端:RHEL6.4 + Oracle 11.2.0.4 目录: 一. 创建外部表 1.1 创建外部表需要的目录 1.2 创建外部表 1.3 创建外部表源文件 1.4 查询外部表 二. 加载 ...
- Oracle的外部表
一.外部表特性 数据文件位于操作系统之外,并且具有一定的格式分割的文本文件或其他类型文件.ORACLE的外部表通过SQL的形式访问数据文件中的数据,数据并不需要加载到数据库中且数据是可读的,所以不用D ...
- 如何利用Oracle外部表导入文本文件的数据
同事最近在忙数据一致性比对工作,需要对不同文本文件中的数据进行比对,有的文件较大,记录较多,如果用普通的文本编辑器打开的话,很显然,会很卡,甚至打不开. 基于此,可将该文本文件的数据导入到数据库中,在 ...
随机推荐
- MPAndroidChart的具体属性方法
android中常用的第三方图表MPAndroidChart的一些具体属性及方法说明 注意:在将折线图转为曲线图时,lineDataSet.setMode(LineDataSet.Mode.CUBIC ...
- android AlertDialog.Builder
AlertDialog的构造方法全部是Protected的,所以不能直接通过new一个AlertDialog来创建出一个AlertDialog. 要创建一个AlertDialog,就要用到AlertD ...
- 反编译CMD命令
1.反XML命令 E:\HuaWei Tools\android\apktool-install-windows-r04-brut1 java -jar AXMLPrinter2.jar guide ...
- SAP MM01 创建物料主数据 [关注公众号后回复MM01获取更多资料]
操作内容 物料主数据,适用于所有有物料编码物料相关信息的系统维护 业务流程 新项目设计冻结后—M公司 PD用-物料编码申请表D-BOM Material Number Application部门内部 ...
- Python中的高级turtle(海龟)作图(续)
四.填色 color 函数有三个参数.第一个参数指定有多少红色,第二个指定有多少绿色,第三个指定有多少蓝色.比如,要得到车子的亮红色,我们用 color(1,0,0),也就是让海龟用百分之百的红色画笔 ...
- Linux系统源码安装软件过程中configure选项-prefix的作用
在linux和unix环境中,源码安装是最常用的软件安装方式,一些软件出了提供源码外,也提供各种发行版的二进制安装包(如基于redhat包管理工具的rpm包),但强烈建议使用源码安装方式. 在linu ...
- 大数据抓取采集框架(摘抄至http://blog.jobbole.com/46673/)
摘抄至http://blog.jobbole.com/46673/ 随着BIG DATA大数据概念逐渐升温,如何搭建一个能够采集海量数据的架构体系摆在大家眼前.如何能够做到所见即所得的无阻拦式采集.如 ...
- Python——eventlet.greenpool
该模块提供对 greenthread 池的支持. greenthread 池提供了一定数量的备用 greenthread ,有效限制了孵化 greenthread 过多导致的内存不足,当池子中没有足够 ...
- ubuntu 14.04 忘记密码怎么办?
ref: https://jingyan.baidu.com/article/8065f87fe20832233024985a.html
- 一款CSS3仿Google Play的垂直菜单
之前分享过一款非常酷的CSS3垂直下拉动画菜单,是多级菜单.今天我们来看一款也是用CSS3制作的垂直菜单,是仿Google Play的菜单,菜单项都带有可爱的小图标,可以先来看看效果图: 当然你可以在 ...