天天看点

PostgreSQL安装Oracle_fdw

Windows版本安装Oracle_fdw

  1. 参考操作步骤 https://blog.csdn.net/ljinxin/article/details/77772587
  2. 前置步骤,拷贝相关文件,共4个文件
lib\oracle_fdw.dll
share\extension\oracle_fdw.control
                oracle_fdw--1.0--1.1.sql
                oracle_fdw--1.1.sql           

Linux安装Oracle_fdw

下载和安装oracle instant client

  1. 下载oracle instant client ,包括3个组件,basic & sdk & sqlplus,并解压
unzip instantclient-basic-linux.x64-19.8.0.0.0dbru.zip
unzip instantclient-sdk-linux.x64-19.8.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip           
  1. 添加tnsname.ora文件到ORACLE_HOME
  2. 配置oracle环境变量到/etc/profile
export ORACLE_HOME=/usr/local/instantclient_19_8
export SQLPATH=/usr/local/instantclient_19_8
export TNS_ADMIN=/usr/local/instantclient_19_8
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARAY_PATH;
export PATH=$PATH:$ORACLE_HOME;           
  1. 使用sqlplus测试是否安装完成,

下载和安装oracle_fdw

  1. 官方下载oracle_fdw
  2. 查找pg_config位置
find / -name pg_config
-- 结果为: /usr/local/pgsql/bin/pg_config           
  1. 修改PG_CONFIG
-- 查看PG_CONFIG配置
cat Makefile | grep PG_CONFIG
-- 本次安装修改
PG_CONFIG = /usr/local/pgsql/bin/pg_config           
  1. 编译并安装 make --> make install, 可使用ldd oracle_fdw.so查看依赖

PostgreSQL中配置oracle_fdw

  1. 配置oracle动态链接库,否则在创建extension时会报错
cd /etc/ld.so.conf.d/
echo "/usr/local/oracle/instantclient_19_8" > oracle-x86_64.conf
ldconfig           
  1. 创建oracle_fdw和外部server
/*注意修改以下代码的ip、用户名和密码*/
SELECT * FROM pg_available_extensions a WHERE a.name LIKE '%oracle%';
/*创建oracle fdw*/
CREATE extension oracle_fdw;

create server testserver foreign data wrapper oracle_fdw options(dbserver '192.168.1.10:1521/orcl');

grant usage on foreign server testserver to postgres;

create user mapping for postgres server testserver options(user 'USERNAME',password '123456');           
  1. 创建外部表,注意schema和table要大写,server与上一步骤创建的server相同
DROP FOREIGN TABLE if exists test_table;
create foreign TABLE IF NOT exists test_table(
ID    VARCHAR(50)
) server testserver options(schema 'USERNAME',table 'TEST_TABLE');

SELECT * FROM test_table;           

参考文档

  1. PostgreSQL的fdw实践
  2. PostgreSQL插件:Oracle_fdw 安装使用,解决ldd动态库依赖
  3. oracle_fdw的安装和使用,解决打不开oracle_fdw.so问题

继续阅读