2
2

More than 5 years have passed since last update.

PostgreSQLにOrafceをインストールする

Last updated at Posted at 2017-12-17

PostgreSQLにOrafceをインストールしよう

OrafceはオラクルDBの関数をPostgreSQLでも使えるようにするextensionです。
いまどきかよ。。。
という気もしますが、古くからみなさまにご愛用いただいているWebシステムではまだ重宝されています。
ちょっと古い環境を用意する必要があり、Orafceを導入した際の手順をまとめておきます。

環境

CentOS7.3
PostgreSQL 9.3

RPMでインストール

makeを使ってインストールする方法もありますが、
自分の環境ではうまく入らず。。。
嬉しいことにRPMが公開されていたので、こちらを利用させていただきます。
https://centos.pkgs.org/7/epel-testing-x86_64/orafce-3.1.2-3.el7.x86_64.rpm.html
こちらからRPMをダウンロードしておきましょう。

ダウンロードが済んだらインストールするだけです。

rpm -ivh orafce-3.1.2-3.el7.x86_64.rpm

自分の環境ではココにインストールされました。

root@orafcedb orafce]# find / -name "*.sql"
/usr/share/pgsql/conversion_create.sql
/usr/share/pgsql/extension/plpgsql--1.0.sql
/usr/share/pgsql/extension/plpgsql--unpackaged--1.0.sql
/usr/share/pgsql/extension/orafce--3.1.sql
/usr/share/pgsql/extension/orafce--unpackaged--3.1.sql
/usr/share/pgsql/extension/orafce.sql
/usr/share/pgsql/extension/uninstall_orafce.sql

PostgreSQLにOrafceを導入

PostgreSQLにログインし、Orafceを導入したいデータベースに接続します。
その後、以下のクエリを実行します。

create extension orafce;

Orafceが入っているか確認します。

\dx
-[ RECORD 1 ]----------------------------------------------------------------------------------------------
Name        | orafce
Version     | 3.1
Schema      | public
Description | Functions and operators that emulate a subset of functions and packages from the Oracle RDBMS
・・・

後は、Oracleの関数を実行できるか確認します。
以下のようにnext_day関数が実行できればOrafce導入成功です。

postgres=# select next_day(current_date, 'saturday');
-[ RECORD 1 ]--------
next_day | 2017-12-16

以下のようにエラーになってしまったら失敗です。
どこか間違っているかもしれません。

postgres=# select next_day(current_date, 'saturday');
ERROR:  function next_day(date, unknown) does not exist
LINE 1: select next_day(current_date, 'saturday');
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

古い環境とはいえ、
動いた時は感動ものですね。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2