postgres=# create extension oracle_fdw; ERROR: could not load library "/opt/pgsql/lib/oracle_fdw.so": libclntsh.so.10.1: cannot open shared object file: No such file or directory
备注:一开始创建 oraclre_fdw 时,提示少了 so 文件,这个比较好解决,只要将对应的 so 文件 copy 到 $PGHOME/lib 下即可,如下:
skytf=# create extension oracle_fdw; CREATE EXTENSION skytf=# /dx List of installed extensions Name | Version | Schema | Description ------------+---------+------------+---------------------------------------- oracle_fdw | 1.0 | public | foreign data wrapper for Oracle access plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (2 rows)
备注:再次测试 oracle_fdw,终于成功了。
Oracle 库创建只读用户
3.1 oracle 创建只读用户并赋只读权限 ( On Oracle)
1 2 3 4 5 6 7 8 9 10 11 12
SQL> CREATE USER read_only IDENTIFIED BY "read_only" 2 DEFAULT TABLESPACE TB_skytf 3 TEMPORARY TABLESPACE TEMP 4 PROFILE DEFAULT 5 ACCOUNT UNLOCK; User created. SQL> GRANT CONNECT TO read_only; Grant succeeded. SQL> grant select on skytf.test_1 to read_Only; Grant succeeded. SQL> conn read_only/read_only; Connected.
3.2 测试 read_only 用户
1 2 3 4 5
SQL> select * from skytf.test_1; ID R ---------- - 1 a 2 b
skytf=# CREATE SERVER oracle_srv skytf-# FOREIGN DATA WRAPPER oracle_fdw skytf-# OPTIONS (dbserver 'primary_1'); CREATE SERVER
4.2 tnsping test
1 2 3 4 5 6 7 8 9
[postgres@primary-01 ~]$ tnsping primary_1 TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production on 03-MAR-2012 15:55:15 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=192.168.1.30) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=MANUA))) OK (10 msec) [postgres@primary-01 ~]$
skytf=> CREATEUSERMAPPINGFOR skytf skytf-> SERVER oracle_srv skytf-> OPTIONS (user'read_only', password'read_only'); CREATEUSERMAPPING skytf=# grant usage on foreign server oracle_srv to skytf; GRANT
4.4 create foreign table
1 2 3 4 5 6 7 8
skytf=# /c skytf skytf You are now connected to database "skytf" as user "skytf". skytf=> CREATE FOREIGN TABLE ft_test_1 ( skytf(> id integer, skytf(> name character varying(20) skytf(> ) SERVER oracle_srv skytf-> OPTIONS (schema 'skytf', table 'test_1'); CREATE FOREIGN TABLE
4.5 查询测试
1 2 3 4 5 6
skytf=> select * from ft_test_1; id | name ----+------ 1 | a 2 | b (2 rows)
备注:终于可以查询到对端 Oracle 库了,到了这步,说明 oracle_fdw 配置成功!
常见问题
常见问题一: 查询外部表报错
1 2 3
skytf=> select * from ft_test_1; ERROR: error connecting to Oracle: OCIEnvCreate failed to create environment handle DETAIL: