我按照此处的说明在PostgreSQL 服务器上安装 Oracle 外部数据包装器oracle_fdw 。
Oracle 版本: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64 位生产,在 Red Hat Linux 7.2 上运行
PostgreSQL 版本: x86_64-unknown-linux-gnu 上的 PostgreSQL 9.4.4,由 gcc (Debian 4.7.2-5) 4.7.2 编译,64 位,在 Debian 7 (wheezy) 上运行。
我能够安装 sqlplus 并成功使用 sqlplus 从 PostgreSQL 服务器连接到 Oracle 服务器,因此连接不是问题。
但是当我尝试创建扩展时,我收到以下错误:
postgres=# create extension oracle_fdw;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
然后我从https://github.com/dalibo/pg_qualstats/issues/1中获取线索,并将 oracle_fdw 添加到 postgresql.conf 中的 shared_preload_libraries 中,如下所示:
shared_preload_libraries = 'oracle_fdw'
但现在我无法重新启动 Postgres:
# service postgresql restart
[....] Restarting PostgreSQL 9.4 database server: main[....] The PostgreSQL server failed to start. Please check the log output: t=2016-09-15 11:05:42 PDT d= h= p=23300 a=FATAL: XX000: invalid cache ID[FAILt=2016-09-15 11:05:42 PDT d= h= p=23300 a=LOCATION: SearchSysCacheList, syscache.c:1219 ... failed!
failed!
查看 /var/log/postgresql/postgresql-9.4-main.log 我只看到这两行:
t=2016-09-15 11:05:42 PDT d= h= p=23300 a=FATAL: XX000: invalid cache ID: 41
t=2016-09-15 11:05:42 PDT d= h= p=23300 a=LOCATION: SearchSysCacheList, syscache.c:1219
从 shared_preload_libraries 中删除 oracle_fdw 允许重新启动 postgres,因此这是导致重新启动失败的原因。所以我从 shared_preload_libraries 中删除了 oracle_fdw 并将其保留在 postgresql.conf 中:
shared_preload_libraries = ''
然后我能够重新启动 Postgres。
以下是完成的确切步骤:
PostgreSQL 服务器的操作系统版本
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"
root@app-4:/# cat /etc/debian_version
7.8
root@app-4:/# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.8 (wheezy)
Release: 7.8
Codename: wheezy
Oracle Instant Client 的安装
使用此处给出的说明安装: https ://help.ubuntu.com/community/Oracle%20Instant%20Client
我从http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下载了以下 rpm 文件:
- oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm
- oracle-instantclient-devel-10.2.0.3-1.x86_64.rpm
- oracle-instantclient-sqlplus-10.2.0.3-1.x86_64.rpm
并使用以下命令将它们安装在 PostgreSQL 服务器上:
# apt-get install alien
# alien -i oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm
# alien -i oracle-instantclient-devel-10.2.0.3-1.x86_64.rpm
# alien -i oracle-instantclient-sqlplus-10.2.0.3-1.x86_64.rpm
确认安装:
# dpkg --list | grep -i oracle
ii oracle-instantclient-basic 10.2.0.3-2 amd64 Instant Client for Oracle Database 11g
ii oracle-instantclient-devel 10.2.0.3-2 amd64 Development headers for Instant Client.
ii oracle-instantclient-sqlplus 10.2.0.3-2 amd64 SQL*Plus for Instant Client.
使用 sqlplus 连接到 Oracle 服务器
# su - postgres
postgres@app-4:~$ sqlplus <ORACLE_USER>/<ORACLE_PASS>@//<ORACLE_HOST>:<ORACLE_PORT>/<SID>
SQL*Plus: Release 10.2.0.3.0 - Production on Fri Sep 16 09:55:02 2016
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select count(*) from <TEST_TABLE>;
COUNT(*)
----------
937530
SQL>
所以这很好用。
安装 oracle_fdw
从http://pgxn.org/dist/oracle_fdw/下载 oracle_fdw 版本 1.4.0 即文件 oracle_fdw-1.4.0.zip
然后解压缩并像这样安装它:
root@app-4:/home/arun/oracle_fdw-1.4.0# ls
CHANGELOG LICENSE META.json oracle_fdw--1.1.sql oracle_fdw.control oracle_fdw.o oracle_gis.c oracle_utils.c README.oracle_fdw TODO
expected Makefile oracle_fdw--1.0--1.1.sql oracle_fdw.c oracle_fdw.h oracle_fdw.so oracle_gis.o oracle_utils.o sql
root@app-4:/home/arun/oracle_fdw-1.4.0# make
...
root@app-4:/home/arun/oracle_fdw-1.4.0# make install
/bin/mkdir -p '/usr/lib/postgresql/9.4/lib'
/bin/mkdir -p '/usr/share/postgresql/9.4/extension'
/bin/mkdir -p '/usr/share/postgresql/9.4/extension'
/bin/mkdir -p '/usr/share/doc/postgresql-doc-9.4/extension'
/usr/bin/install -c -m 755 oracle_fdw.so '/usr/lib/postgresql/9.4/lib/oracle_fdw.so'
/usr/bin/install -c -m 644 oracle_fdw.control '/usr/share/postgresql/9.4/extension/'
/usr/bin/install -c -m 644 oracle_fdw--1.1.sql oracle_fdw--1.0--1.1.sql '/usr/share/postgresql/9.4/extension/'
/usr/bin/install -c -m 644 README.oracle_fdw '/usr/share/doc/postgresql-doc-9.4/extension/'
在 Postgres 中创建扩展
root@app-4:/# su - postgres
postgres@app-4:~$ psql
psql (9.4.4)
Type "help" for help.
postgres=# create extension oracle_fdw;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!> \q
堆栈跟踪
我按照 Laurenz Albe 在他的回答中的建议安装了 GNU 调试器(gdb),并得到了以下堆栈跟踪(目前没有调试符号):
Continuing.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
#0 0x0000000000000000 in ?? ()
#1 0x00007ff657dfcc99 in DirectFunctionCall1Coll ()
#2 0x00007ff657de19a9 in ?? ()
#3 0x00007ff657de3037 in SearchCatCacheList ()
#4 0x00007ff4c5fcce7d in _PG_init () at oracle_fdw.c:648
#5 0x00007ff657dfb717 in ?? ()
#6 0x00007ff657dfc051 in load_external_function ()
#7 0x00007ff657b6b486 in fmgr_c_validator ()
#8 0x00007ff657dfdeba in OidFunctionCall1Coll ()
#9 0x00007ff657b6aedc in ProcedureCreate ()
#10 0x00007ff657bcf645 in CreateFunction ()
#11 0x00007ff657d14e73 in ?? ()
#12 0x00007ff657d140c7 in standard_ProcessUtility ()
#13 0x00007ff657bc89ed in ?? ()
#14 0x00007ff657bc98de in CreateExtension ()
#15 0x00007ff657d154c1 in ?? ()
#16 0x00007ff657d140c7 in standard_ProcessUtility ()
#17 0x00007ff657d11243 in ?? ()
#18 0x00007ff657d11e96 in ?? ()
#19 0x00007ff657d12b3d in PortalRun ()
#20 0x00007ff657d0fb1a in PostgresMain ()
#21 0x00007ff657acbdad in ?? ()
#22 0x00007ff657caf351 in PostmasterMain ()
#23 0x00007ff657acccba in main ()
Continuing.
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
更新:我能够在运行在 debian 8(8.6,jessie)上的 Postgres 9.4.9 上安装扩展。我使用了 Oracle 即时客户端版本 12.1.0.2.0-1 和 oracle_fdw 版本 1.5。