2025年6月27日金曜日

OML4R 2.0を実行する環境を作成する

OML4R(Oracle Machine Learning for R)の動作を確認するため、手元のMacbook上に環境を作成してみました。

TL;DR

Oracle Database Free 23aiのコンテナにOML4Rを構成するスクリプトを、リポジトリapex-podman-setupに追加しました。


以下の手順で呼び出します。
git clone https://github.com/ujnak/apex-podman-setup.git
cd apex-podman-setup
oml4r-supporting-linux-x86-64-2.0.zipをディレクトリoml以下にダウンロードします。ダウンロードしたらコンテナを作成して、構成スクリプトを実行します。
podman run -d --name oml4r-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest
podman exec oml4r-db ./work/config_oml4r.sh
以上で構成完了です。

OML4R向けのデータベース・ユーザーは、ユーザーSYSでSQLスクリプトcreate_user_for_oml.sqlを実行して作成します。上記の手順ではSYSのパスワードは設定されていないため、最初にSYSのパスワードを設定します。
podman exec oml4py-db ./setPassword.sh [SYSのパスワード]
sql sys/[SYSのパスワード]@localhost/freepdb1 as sysdba
@create_user_for_oml [ユーザー名] [パスワード]


構成手順の説明



参照したドキュメントは以下です。

Oracle® Machine Learning for R Installation and Administration Guide

最初にシステム要件を確認します。
  • CPUのアーキテクチャはx86-64のみ。ARMは未対応。
  • OSはOracle Linux 7または8。
  • OML4R 2.0は19c、21cおよび23c(23ai)をサポート。
今回は、以下の環境でOML4Rが動く環境を作成します。
  • Intel CPUのMacbook Pro
  • Oracle Database 23ai Freeのコンテナ(podmanで動かします)
以下より作業手順を紹介します。

Oracle Database 23ai Freeのコンテナ・イメージをダウンロードします。

podman pull container-registry.oracle.com/database/free:latest

% podman pull container-registry.oracle.com/database/free:latest

Trying to pull container-registry.oracle.com/database/free:latest...

Getting image source signatures

Copying blob sha256:3c19df83dc536c431f1f991013d53f88157d03afed4452c014b3a0deb32add62

Copying blob sha256:7ce287ddcf023475b16b98c11a145816110e4870844f6008eb11fc12cb98bc13

Copying blob sha256:60b151ee286ca7b9cf8876c091384ce0e3f46f723f383b74d573f5f3c8a83181

Copying blob sha256:67273d20686cb6adc472d07c54f5b2ecacab066d73d41b419e64be5141d9c063

Copying blob sha256:769e9048b21fc9ec5c1af97cb44cf1298993838fee496c6a6cf471cbd9656e0c

Copying blob sha256:a723d4eb80abb9526bef6c15e008956c6942b5b55615df9f04efd3f712b4b36e

Copying blob sha256:18c61db4fa1af28adfb01c770f0c8d8e367ca55026f565bbb2f604fb983b223d

Copying blob sha256:c321a0e5c325a0dbaa799c1e57f890581809fc70e16be7cb87623f123539e313

Copying blob sha256:fb5a2405efd168f49f8b9ef5d65df63abcc4e71805762287ea271ca04152c917

Copying blob sha256:376386880722b05af54cf21bd65f395f9fb7cfac97faec27daf1e0a974ce3490

Copying blob sha256:7cddbcf7b07fea3e32233ac910ac24edcbea2432f167475cfcd6956ca6f207f1

Copying blob sha256:2848595a81954b79fbf33d59118206544dcbad85caa812b5e6d4b2b791ee8080

Copying blob sha256:4be01f5508ceb77530a1ea7f67fe0e37dc6872a9b0d82b211c2c3cfd918b0613

Copying blob sha256:2b69d3f60317f457eb4e39272eaf0bd325a1cb93ec51688a827d48a9c751cc64

Copying blob sha256:09677a4c8b1dd39d40d9af24770ee31ed05080d809ed431db53dcf8c39bf5b3d

Copying blob sha256:11a1c1f55c592ed25186b19370ad9199f97399e26976d0ee871eb1294de29bd8

Copying blob sha256:8324f2f6589bff8d94395f238ad2b468d5e2de61e01c200ade98b3cf15775a09

Copying blob sha256:da169847304113d28f334ed2689f30b3ad43ec42d19b3660e50916f05b91fd98

Copying blob sha256:954a67596b3b39218744babefe4e0429c12e6fc5a5ff7dc1f03fca56b6e1b50b

Copying blob sha256:836b5e4a04390544c4723037a76eec01aec8871375c1c1d8a6a3b9501942f9b6

Copying blob sha256:1ed5527365e9e7916f19f06fcbb05fa912f7ff2473ab9086ad5db8c2c6083dcb

Copying blob sha256:9339d36e49cd39cc09167f8fea58f3e8295ba7eeb23876bedc508454cd01be43

Copying config sha256:98201d89c4b33275f2ebb5c15d894c44d7e3273a23ed3b2435c5b329318db078

Writing manifest to image destination

98201d89c4b33275f2ebb5c15d894c44d7e3273a23ed3b2435c5b329318db078

% 


作業ディレクトリを作成して移動します。今回の作業ディレクトリはoml4rとします。

mkdir oml4r
cd oml4r

% mkdir oml4r

% cd oml4r

oml4r % 


Oracle Database Freeのコンテナとしてoml4r-dbを作成します。現在の作業ディレクトリをコンテナ内の/home/oracle/workにマウントしています。

podman run -d --name oml4r-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest

oml4r % podman run -d --name oml4r-db -p 1521:1521 -v $PWD:/home/oracle/work container-registry.oracle.com/database/free:latest

a6ce657a29ccc895e78927422276ffbae08f069bebd3b717fb6d336c8e3d0182

oml4r % 


コンテナの作成状況を確認します。

podman logs oml4r-db -f

DATABASE IS READY TO USE!と表示されていれば、コンテナの作成が完了し利用できる状態です。

oml4r % podman logs oml4r-db -f

Starting Oracle Net Listener.

Oracle Net Listener started.

Starting Oracle Database instance FREE.

Oracle Database instance FREE started.


The Oracle base remains unchanged with value /opt/oracle

#########################

DATABASE IS READY TO USE!

#########################

The following output is now a tail of the alert.log:

2025-06-28T07:45:12.519111+00:00

PDB$SEED(2):Opening pdb with Resource Manager plan: DEFAULT_PLAN

(3):--ATTENTION--

(3):PARALLEL_MAX_SERVERS (with value 1) is insufficient. This may affect transaction recovery performance.

Modify PARALLEL_MAX_SERVERS parameter to a value > 4 (= parallel servers count computed from parameter FAST_START_PARALLEL_ROLLBACK) in PDB ID 3

FREEPDB1(3):Autotune of undo retention is turned on. 

2025-06-28T07:45:13.742739+00:00

FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN

Completed: Pluggable database FREEPDB1 opened read write 

Completed: ALTER DATABASE OPEN

2025-06-28T07:45:15.105222+00:00

===========================================================

Dumping current patch information

===========================================================

No patches have been applied

===========================================================



作成されたコンテナに接続し、Rをインストールします。


R 4.0.5のインストール



インストール・ガイドの以下の手順を実施します。

3.2.1 Install Oracle R Distribution on Oracle Linux 8 Using Dnf

コンテナoml4r-dbに接続します。

podman exec -it oml4r-db bash

oml4r % podman exec -it oml4r-db bash

bash-4.2$ 


Oracle Cloudのコンピュート・インスタンスであれば、ociregionの内容が-us-phoenix-1でもyumリポジトリにアクセスできますが、そうでない場合はociregionの内容を消去します。

su -c "echo '' > /etc/dnf/vars/ociregion"
cat /etc/dnf/vars/ociregion

bash-4.4$ su -c "echo '' > /etc/dnf/vars/ociregion"

bash-4.4$ cat /etc/dnf/vars/ociregion


bash-4.4$ 


Yumリポジトリのol8_codeready_builderol8_addonsを有効にします。

su
yum-config-manager --enable ol8_codeready_builder
yum-config-manager --enable ol8_addons


bash-4.4$ su

[root@a6ce657a29cc oracle]# yum-config-manager --enable ol8_codeready_builder

[root@a6ce657a29cc oracle]# yum-config-manager --enable ol8_addons

[root@a6ce657a29cc oracle]#


R-4.0.5とサポート・パッケージのCairoが必要とするパッケージcairo-develインストールします。

dnf install R-4.0.5 cairo-devel

[root@6de79cfd09a8 oracle]# dnf install R-4.0.5 cairo-devel

Oracle Linux 8 BaseOS Latest (x86_64)                                           9.4 MB/s | 102 MB     00:10    

Oracle Linux 8 Application Stream (x86_64)                                      9.1 MB/s |  71 MB     00:07    

Oracle Linux 8 CodeReady Builder (x86_64) - Unsupported                         8.2 MB/s |  13 MB     00:01    

Oracle Linux 8 Addons (x86_64)                                                  9.3 MB/s |  38 MB     00:04    

Oracle Linux 8 Development Packages (x86_64)                                    9.2 MB/s | 214 MB     00:23    

Last metadata expiration check: 0:00:03 ago on Sat Jun 28 09:14:45 2025.

Dependencies resolved.

================================================================================================================

 Package                          Arch   Version                                    Repository             Size

================================================================================================================

Installing:

 R                                x86_64 4.0.5-1.0.1.el8                            ol8_addons             21 k

 cairo-devel                      x86_64 1.15.12-6.el8                              ol8_appstream         273 k

Installing dependencies:

 R-core                           x86_64 4.0.5-1.0.1.el8                            ol8_addons             59 M

 R-devel                          x86_64 4.0.5-1.0.1.el8                            ol8_addons            102 k

 adobe-mappings-cmap              noarch 20171205-3.el8                             ol8_appstream         2.1 M

 adobe-mappings-cmap-deprecated   noarch 20171205-3.el8                             ol8_appstream         118 k

 adobe-mappings-pdf               noarch 20180407-1.el8                             ol8_appstream         707 k

 annobin                          x86_64 11.13-2.0.6.el8                            ol8_appstream         972 k

 avahi-glib                       x86_64 0.7-27.el8_10.1                            ol8_baseos_latest      14 k

 avahi-libs                       x86_64 0.7-27.el8_10.1                            ol8_baseos_latest      61 k


[中略]


  xorg-x11-font-utils-1:7.5-41.el8.x86_64

  xorg-x11-proto-devel-2020.1-3.el8.noarch

  xorg-x11-server-utils-7.7-27.el8.x86_64

  zip-3.0-23.el8.x86_64        

  zlib-devel-1.2.11-25.el8.x86_64

  zziplib-0.13.68-13.el8_10.x86_64


Complete!

[root@6de79cfd09a8 oracle]# exit

exit

bash-4.4$ 


以上でR-4.0.5のインストールが完了しました。

スーパー・ユーザーから一般ユーザーに戻ります。


OML4R Serverのインストール



OML4R Serverをインストールします。

インストール・ガイドの以下の手順を実施します。

4.3 Install Oracle Machine Learning for R Server for Oracle Database 23ai

2025年7月4日追記 ----

OML4RをCDBにインストールしないとデータベースの起動時に以下のエラーが発生し、PDBがRESTRICTEDモードでオープンします。そのためOML4RのCDBへのインストールは必須です。

FREEPDB1(3):--ATTENTION--

FREEPDB1(3):Errors reported while opening PDB (ContainerId: 3) and have been recorded in pdb_alert$ table.

FREEPDB1(3) Error Violation: OPTION, Cause: Database option OML4R mismatch: PDB installed version 23.0.0.0.0. CDB is not installed or enabled., Action: Fix the database option in the PDB or the CDB


----

初めにOML4R ServerをCDBにインストールします。

cd $ORACLE_HOME/R/server
sqlplus / as sysdba
spool install_root.txt
show con_name
@rqcfg.sql
SYSAUX
TEMP
/opt/oracle/product/23ai/dbhomeFree
/usr/lib64/R

rqcfg.sqlに与える引数はドキュメントの以下の記述に従って指定します。Oracle Database 23ai Freeのコンテナが前提であれば、上記のまま変更不要です。
The first parameter is the tablespace for the RQSYS schema, the second parameter is the temporary tablespace for the RQSYS schema, the third parameter is the hard-coded value for ORACLE_HOME, and the fourth parameter is the hard-coded value for R_HOME.

bash-4.4$ cd $ORACLE_HOME/R/server

bash-4.4$ sqlplus / as sysdba


SQL*Plus: Release 23.0.0.0.0 - Production on Sat Jun 28 08:15:46 2025

Version 23.8.0.25.04


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04


SQL> spool install_root.txt

SQL> show con_name


CON_NAME

------------------------------

CDB$ROOT

SQL> @rqcfg.sql


Session altered.


Enter value for 1: SYSAUX

Enter value for 2: TEMP

Enter value for 3: /opt/oracle/product/23ai/dbhomeFree

Enter value for 4: /usr/lib64/R


PL/SQL procedure successfully completed.







Session altered.



User created.



Grant succeeded.


[中略]


Session altered.



PL/SQL procedure successfully completed.



Session altered.



Session altered.


SQL> 


続けてOML4R Serverを作成済みのPDB、FREEPDB1にインストールします。rqcfg.sqlの引数の第1と第2パラメータの入力は省略されます。

alter session set container = FREEPDB1;
spool install_pdb.txt
show con_name
@rqcfg.sql
/opt/oracle/product/23ai/dbhomeFree
/usr/lib64/R


SQL> alter session set container = FREEPDB1;


Session altered.


SQL> spool install_pdb.txt

SQL> show con_name


CON_NAME

------------------------------

FREEPDB1

SQL> @rqcfg.sql


Session altered.


Enter value for 3: /opt/oracle/product/23ai/dbhomeFree

Enter value for 4: /usr/lib64/R


PL/SQL procedure successfully completed.







Session altered.



User created.



Grant succeeded.



Procedure created.



Procedure created.


No errors.


Role created.



Role created.



Table created.


[中略]


Session altered.



PL/SQL procedure successfully completed.



Session altered.



Session altered.


SQL> 


以上でOML4R Serverのインストールは完了です。

一旦コンテナを抜けます。

SQL> exit

Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04

bash-4.4$ exit

exit

oml4r %  



Rのサポート・パッケージのインストール



Rのサポート・パッケージをインストールします。

インストール・ガイドの以下の手順を実施します。

6.4.1 Install the Supporting Packages on Linux

Oracle Machine Learning for R Downloadsのページを開き、OML4R 2.0 (R-4.0.5)のSupportingをダウンロードします。


oml4r-supporting-linux-x86-64-2.0.zipがダウンロードされるので、ホストの作業ディレクトリoml4r以下に配置します。

コンテナoml4r-dbに接続し、ホストのディレクトリoml4rをマウントしているディレクトリworkへ移動します。

podman exec -it oml4r-db bash
cd work
ls

oml4r % podman exec -it oml4r-db bash

bash-4.4$ cd work

bash-4.4$ ls

oml4r-supporting-linux-x86-64-2.0.zip

bash-4.4$ 


oml4r-supporting-linux-x86-64-2.0.zipを解凍します。

unzip oml4r-supporting-linux-x86-64-2.0.zip

bash-4.4$ unzip oml4r-supporting-linux-x86-64-2.0.zip 

Archive:  oml4r-supporting-linux-x86-64-2.0.zip

  inflating: supporting/Cairo_1.5-15_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/DBI_1.1.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/R6_2.5.1_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/ROracle_1.4-1_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/arules_1.7-3_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/assertthat_0.2.1_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/cli_3.3.0_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/crayon_1.5.1_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/dplyr_1.0.9_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/ellipsis_0.3.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/fansi_1.0.3_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/generics_0.1.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/glue_1.6.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/lazyeval_0.2.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/lifecycle_1.0.1_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/magrittr_2.0.3_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/pillar_1.7.0_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/pkgconfig_2.0.3_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/png_0.1-8_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/purrr_0.3.4_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/rlang_1.0.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/statmod_1.5.0_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/tibble_3.1.7_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/tidyselect_1.1.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/utf8_1.2.2_R_x86_64-unknown-linux-gnu.tar.gz  

  inflating: supporting/vctrs_0.4.1_R_x86_64-unknown-linux-gnu.tar.gz  

bash-4.4$ 


コマンドOREに実行フラグを立てます。

chmod 755 /opt/oracle/product/23ai/dbhomeFree/bin/ORE

bash-4.4$ chmod 755 /opt/oracle/product/23ai/dbhomeFree/bin/ORE

bash-4.4$ 


サポート・パッケージのZIPファイルを解凍して作成されたディレクトリsupportingへ移動します。

cd supporting

bash-4.4$ cd supporting

bash-4.4$ 


サーバーにサポート・パッケージをインストールします。

ORE CMD INSTALL *

bash-4.4$ ORE CMD INSTALL *

* installing to library '/opt/oracle/product/23ai/dbhomeFree/R/library'

* installing *binary* package 'Cairo' ...

* DONE (Cairo)


* installing *binary* package 'DBI' ...

* DONE (DBI)


* installing *binary* package 'R6' ...

* DONE (R6)


* installing *binary* package 'ROracle' ...

* DONE (ROracle)


* installing *binary* package 'arules' ...

* DONE (arules)


* installing *binary* package 'assertthat' ...

* DONE (assertthat)


* installing *binary* package 'cli' ...

* DONE (cli)


* installing *binary* package 'crayon' ...

* DONE (crayon)


* installing *binary* package 'dplyr' ...

* DONE (dplyr)


* installing *binary* package 'ellipsis' ...

* DONE (ellipsis)


* installing *binary* package 'fansi' ...

* DONE (fansi)


* installing *binary* package 'generics' ...

* DONE (generics)


* installing *binary* package 'glue' ...

* DONE (glue)


* installing *binary* package 'lazyeval' ...

* DONE (lazyeval)


* installing *binary* package 'lifecycle' ...

* DONE (lifecycle)


* installing *binary* package 'magrittr' ...

* DONE (magrittr)


* installing *binary* package 'pillar' ...

* DONE (pillar)


* installing *binary* package 'pkgconfig' ...

* DONE (pkgconfig)


* installing *binary* package 'png' ...

* DONE (png)


* installing *binary* package 'purrr' ...

* DONE (purrr)


* installing *binary* package 'rlang' ...

* DONE (rlang)


* installing *binary* package 'statmod' ...

* DONE (statmod)


* installing *binary* package 'tibble' ...

* DONE (tibble)


* installing *binary* package 'tidyselect' ...

* DONE (tidyselect)


* installing *binary* package 'utf8' ...

* DONE (utf8)


* installing *binary* package 'vctrs' ...

* DONE (vctrs)

bash-4.4$ 


クライアントにサポート・パッケージをインストールします。スーパー・ユーザーで実行します。

su
R --vanilla CMD INSTALL *

bash-4.4$ su

[root@a6ce657a29cc supporting]# R --vanilla CMD INSTALL *

* installing to library '/usr/lib64/R/library'

* installing *binary* package 'Cairo' ...

* DONE (Cairo)


* installing *binary* package 'DBI' ...

* DONE (DBI)


* installing *binary* package 'R6' ...

* DONE (R6)


* installing *binary* package 'ROracle' ...

* DONE (ROracle)


* installing *binary* package 'arules' ...

* DONE (arules)


* installing *binary* package 'assertthat' ...

* DONE (assertthat)


* installing *binary* package 'cli' ...

* DONE (cli)


* installing *binary* package 'crayon' ...

* DONE (crayon)


* installing *binary* package 'dplyr' ...

* DONE (dplyr)


* installing *binary* package 'ellipsis' ...

* DONE (ellipsis)


* installing *binary* package 'fansi' ...

* DONE (fansi)


* installing *binary* package 'generics' ...

* DONE (generics)


* installing *binary* package 'glue' ...

* DONE (glue)


* installing *binary* package 'lazyeval' ...

* DONE (lazyeval)


* installing *binary* package 'lifecycle' ...

* DONE (lifecycle)


* installing *binary* package 'magrittr' ...

* DONE (magrittr)


* installing *binary* package 'pillar' ...

* DONE (pillar)


* installing *binary* package 'pkgconfig' ...

* DONE (pkgconfig)


* installing *binary* package 'png' ...

* DONE (png)


* installing *binary* package 'purrr' ...

* DONE (purrr)


* installing *binary* package 'rlang' ...

* DONE (rlang)


* installing *binary* package 'statmod' ...

* DONE (statmod)


* installing *binary* package 'tibble' ...

* DONE (tibble)


* installing *binary* package 'tidyselect' ...

* DONE (tidyselect)


* installing *binary* package 'utf8' ...

* DONE (utf8)


* installing *binary* package 'vctrs' ...

* DONE (vctrs)

Making 'packages.html' ... done

[root@a6ce657a29cc supporting]# exit

exit

bash-4.4$ 


スーパー・ユーザーから一般ユーザーに戻ります。

以上でサポート・パッケージのインストールは完了です。


OML4R Serverの動作検証



インストールしたOML4R Serverの検証を行います。

コンテナ作成時にSYSのパスワードを指定しなかったため、SYSのパスワードがランダムな文字列になっています。これからの作業に支障があるため、データベースのSYSのパスワードを設定します。

cd ~
./setPassword.sh [SYSのパスワード]

bash-4.2$ cd ~

bash-4.4$ ./setPassword.sh **********

The Oracle base remains unchanged with value /opt/oracle


SQL*Plus: Release 23.0.0.0.0 - Production on Sat Jun 28 08:56:36 2025

Version 23.8.0.25.04


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04


SQL> 

User altered.


SQL> 

User altered.


SQL> 

Session altered.


SQL> 

User altered.


SQL> Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04

bash-4.4$ 


確認作業に使用するユーザーを作成します。

OML4Rではユーザーを作成するスクリプトrquser.sqlを提供しています。
しかし用途がOML4Rだけというのもあまりないので、一般的なコマンドを実行してデータベース・ユーザーを作成します。

sqlplus sys/[SYSのパスワード]@localhost/freepdb1 as sysdba

bash-4.4$ sqlplus sys/*********@localhost/freepdb1 as sysdba


SQL*Plus: Release 23.0.0.0.0 - Production on Sat Jun 28 08:57:31 2025

Version 23.8.0.25.04


Copyright (c) 1982, 2025, Oracle.  All rights reserved.



Connected to:

Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04


SQL> 


データベース・ユーザーとしてOMLUSERを作成し、必要な権限を与えます。

create user omluser identified by [パスワード] default tablespace users temporary tablespace temp;
alter user omluser quota unlimited on users;
grant db_developer_role, rqadmin to omluser;
grant create mining model to omluser;

SQL> create user omluser identified by ******** default tablespace users temporary tablespace temp;


User created.


SQL> alter user omluser quota unlimited on users;


User altered.


SQL> grant db_developer_role, rqadmin to omluser;


Grant succeeded.


SQL> grant create mining model to omluser;


Grant succeeded.


SQL> exit

Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.8.0.25.04

bash-4.4$ 


インストール・ガイドの以下の手順を実施します。

LD_LIBRARY_PATHに$ORACLE_HOME/libを追加します。

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

bash-4.2$ export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

bash-4.2$ 


OREを起動します。

ORE

bash-4.4$ ORE


Oracle Distribution of R version 4.0.5  (--) -- "Shake and Throw"

Copyright (C)  The R Foundation for Statistical Computing

Platform: x86_64-pc-linux-gnu (64-bit)


R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type 'license()' or 'licence()' for distribution details.


R is a collaborative project with many contributors.

Type 'contributors()' for more information and

'citation()' on how to cite R or R packages in publications.


Type 'demo()' for some demos, 'help()' for on-line help, or

'help.start()' for an HTML browser interface to help.

Type 'q()' to quit R.


You are using Oracle's distribution of R. Please contact

Oracle Support for any problems you encounter with this

distribution.


> 


ライブラリをロードします。

library(ORE)

> library(ORE)

Loading required package: OREbase

Loading required package: OREcommon


Attaching package: 'OREbase'


The following objects are masked from 'package:base':


    cbind, data.frame, eval, interaction, order, paste, pmax, pmin,

    rbind, table


Loading required package: OREembed

Loading required package: OREstats

Loading required package: OREgraphics

Registered S3 methods overwritten by 'OREgraphics':

  method          from    

  boxplot.formula graphics

  cdplot.formula  graphics

  pairs.formula   graphics

  plot.formula    graphics

  lines.formula   graphics

  points.formula  graphics

  text.formula    graphics


Attaching package: 'OREgraphics'


The following object is masked from 'package:grDevices':


    xy.coords


Loading required package: OREeda

Loading required package: OREmodels

Loading required package: OREdm

Loading required package: OREpredict

Loading required package: ORExml

Registered S3 method overwritten by 'ORE':

  method                      from 

  print.help_files_with_topic utils

> 


データベースに先ほど作成したユーザーOMLUSERで接続します。

ore.connect("OMLUSER", password="パスワード", service_name="FREEPDB1", host="localhost", all=TRUE)

> ore.connect("OMLUSER", password="*******", service_name="FREEPDB1", host="localhost", all=TRUE)

> 


ドキュメントに記載されている検証スクリプトを実行します。
## Is the OML4R client connected to the OML4R server? ## The output of this function should be TRUE. ore.is.connected() ## List the available database tables. ore.ls() ## Push an R dataframe to a database table. df <- data.frame(a="abc", b=1.456, c=TRUE, d=as.integer(1)) of <- ore.push(df) ## Run the self-contained example code in the help files associated with the following functions. ## The examples should not return any errors. example("ore.odmAI") ## Builds an OML4SQL attribute importance model. example("ore.doEval") ## Runs an embedded R execution function.

> ## Is the OML4R client connected to the OML4R server?

> ## The output of this function should be TRUE.

> ore.is.connected()

[1] TRUE

> 

> ## List the available database tables.

> ore.ls()

character(0)

> 

> ## Push an R dataframe to a database table.

> df <- data.frame(a="abc",

+                 b=1.456,

+                 c=TRUE,

+                 d=as.integer(1))

> of <- ore.push(df)

> 

> ## Run the self-contained example code in the help files associated with the following functions.

> ## The examples should not return any errors.

> example("ore.odmAI")     ## Builds an OML4SQL attribute importance model.


or.dAI>   IRIS <- ore.push(iris)


or.dAI>   ore.odmAI(Species ~ ., IRIS)


Call:

ore.odmAI(formula = Species ~ ., data = IRIS)


Importance: 

             importance rank

Petal.Width   1.0509353    1

Petal.Length  1.0306334    2

Sepal.Length  0.4548240    3

Sepal.Width   0.1915138    4


> example("ore.doEval")    ## Runs an embedded R execution function.


or.dEv> ## ore.doEval

or.dEv> eval1 <- ore.doEval(function() "Hello, world")


or.dEv> eval2 <-

or.dEv+   ore.doEval(function()

or.dEv+              data.frame(x = "Hello, world", stringsAsFactors = FALSE))


or.dEv> eval3 <-

or.dEv+   ore.doEval(function()

or.dEv+              data.frame(x = "Hello, world", stringsAsFactors = FALSE),

or.dEv+              FUN.VALUE =

or.dEv+              data.frame(x = character(), stringsAsFactors = FALSE))


or.dEv> out.df <- data.frame(x = character(), y = raw(), stringsAsFactors = FALSE)


or.dEv> attr(out.df$x, "ora.type") <- "clob"


or.dEv> attr(out.df$y, "ora.type") <- "blob"


or.dEv> eval4 <- 

or.dEv+   ore.doEval(function() {

or.dEv+              res <- data.frame(x = "Hello, world",stringsAsFactors = FALSE)

or.dEv+              res$y[[1L]] <- charToRaw("Hello, world")

or.dEv+              res},

or.dEv+              FUN.VALUE = out.df)


or.dEv> eval1

[1] "Hello, world"


or.dEv> class(eval1)  # ore.object

[1] "ore.object"

attr(,"package")

[1] "OREembed"


or.dEv> eval2

             x

1 Hello, world


or.dEv> class(eval2)  # ore.object

[1] "ore.object"

attr(,"package")

[1] "OREembed"


or.dEv> eval3

             x

1 Hello, world


or.dEv> class(eval3)  # ore.frame

[1] "ore.frame"

attr(,"package")

[1] "OREbase"


or.dEv> eval4$x

[1] "Hello, world"


or.dEv> rawToChar(ore.pull(eval4$y))

[1] "Hello, world"


or.dEv> ## copy data to the database

or.dEv> IRIS <- ore.push(iris)


or.dEv> ## ore.groupApply

or.dEv> grpAp1 <-

or.dEv+   ore.groupApply(IRIS, IRIS$Species,

or.dEv+                  function(df)

or.dEv+                  if(nrow(df) == 0)

or.dEv+                      NULL

or.dEv+                  else

or.dEv+                      summary(lm(Sepal.Length ~ .,  data = df[1:4])),

or.dEv+                  parallel = TRUE)


or.dEv> grpAp2 <-

or.dEv+   ore.groupApply(IRIS, IRIS$Species,

or.dEv+                  function(df) {

or.dEv+                      if (nrow(df) == 0) {

or.dEv+                          species <- character()

or.dEv+                          cf <- numeric()

or.dEv+                          names(cf) <- character()

or.dEv+                      } else {

or.dEv+                          species <- as.character(df$Species[1])

or.dEv+                          cf <- coef(lm(Sepal.Length ~ .,

or.dEv+                                        data = df[1:4]))

or.dEv+                      }

or.dEv+                      data.frame(Species = species,

or.dEv+                                 CoefName = names(cf),

or.dEv+                                 CoefValue = unname(cf),

or.dEv+                                 stringsAsFactors = FALSE)

or.dEv+                  },

or.dEv+                  FUN.VALUE =

or.dEv+                  data.frame(Species = character(),

or.dEv+                             CoefName = character(),

or.dEv+                             CoefValue = numeric(),

or.dEv+                             stringsAsFactors = FALSE),

or.dEv+                  parallel = TRUE)


or.dEv> class(grpAp1)  # ore.list

[1] "ore.list"

attr(,"package")

[1] "OREembed"


or.dEv> class(grpAp2)  # ore.frame

[1] "ore.frame"

attr(,"package")

[1] "OREbase"


or.dEv> ## ore.indexApply

or.dEv> ore.indexApply(5, function(i) i)

$`1`

[1] 1


$`2`

[1] 2


$`3`

[1] 3


$`4`

[1] 4


$`5`

[1] 5



or.dEv> if (interactive())

or.dEv+     ore.indexApply(5, function(i) summary(rnorm(100)), parallel = TRUE)

$`1`

    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 

-2.94933 -0.80292 -0.01287 -0.12134  0.68057  1.99584 


$`2`

    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 

-2.07734 -0.73430 -0.10199 -0.08626  0.62752  2.00369 


$`3`

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 

-2.9616 -0.5587  0.1533  0.1705  0.9220  2.8846 


$`4`

    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 

-2.14695 -0.59096  0.05546  0.02915  0.66951  2.63772 


$`5`

    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 

-2.82707 -0.71070 -0.03071  0.01168  0.76839  2.29628 



or.dEv> ## ore.rowApply

or.dEv> # create a classification tree for iris data

or.dEv> library(rpart)


or.dEv> irisRpart <- rpart(Species ~ ., data = iris)


or.dEv> irisPred <-

or.dEv+   ore.rowApply(IRIS,

or.dEv+                function(df, model) {

or.dEv+                    library(rpart)

or.dEv+                    cbind(df, PRED = predict(model, df, type = "class"))

or.dEv+                }, model = irisRpart,

or.dEv+                FUN.VALUE =

or.dEv+                cbind(iris[integer(),], PRED = character()),

or.dEv+                rows = 50, parallel = TRUE)


or.dEv> ## ore.tableApply

or.dEv> ore.tableApply(IRIS, function(df) summary(df))

  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   

 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  

 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  

 Median :5.800   Median :3.000   Median :4.350   Median :1.300  

 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  

 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  

 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  

   Species         

 Length:150        

 Class :character  

 Mode  :character  

                   

                   

                   

Warning messages:

1: ORE object has no unique key - using random order 

2: ORE object has no unique key - using random order 

3: ORE object has no unique key - using random order 

> 


正常に実行できることが確認できたら、OML4Rのインストールは完了です。