■ 前提
- OCI(Oracle Cloud Infrastructure) / ADB(Autonomous Database)のセットアップが完了している
- unixODBCのインストールに必要な以下のツールがインストールされている(makeでInstallするとき)
- automake
- autoconf
- gcc
- libtool
- make
- Oracle Instant Clientのインストールに必要な要件がクリアされている
■ 導入ステップ
Oracle Instant Client のインストール
- Database Clientのためのユーザ、グループの構成
# /usr/sbin/groupadd -g 54321 oinstall
# /usr/sbin/useradd -u 54321 -g oinstall oracle
※ uidやgidは環境に合わせて任意に設定する
※ これ以降の作業は基本的に、oracleユーザにて作業する前提とする
- 関連するファイルをダウンロード
ここでは現時点で(21/7/15)の19cの最新版をダウンロード
Basic Package : instantclient-basic-linux.x64-19.11.0.0.0dbru.zip
ODBC Package : instantclient-odbc-linux.x64-19.11.0.0.0dbru.zip
SQLPlus : instantclient-sqlplus-linux.x64-19.11.0.0.0dbru.zip
Tool(SQLLoader/Data Pump) : instantclient-tools-linux.x64-19.11.0.0.0dbru.zip
※ SQL*Plusは必須ではなくOption。必要に応じてInstallする
curlを使ったダウンロード例
$ sudo mkdir -p /opt/oracle
$ sudo chown oracle:oinstall /opt/oracle
$ cd /opt/oracle
$ curl -L -O https://download.oracle.com/otn_software/linux/instantclient/1911000/oracle-instantclient19.11-basic-19.11.0.0.0-1.x86_64.rpm
$ curl -L -O https://download.oracle.com/otn_software/linux/instantclient/1911000/oracle-instantclient19.11-odbc-19.11.0.0.0-1.x86_64.rpm
$ curl -L -O https://download.oracle.com/otn_software/linux/instantclient/1911000/oracle-instantclient19.11-sqlplus-19.11.0.0.0-1.x86_64.rpm
$ curl -L -O https://download.oracle.com/otn_software/linux/instantclient/1911000/oracle-instantclient19.11-tools-19.11.0.0.0-1.x86_64.rpm
上記ファイルをunzip
$ unzip instantclient-basic-linux.x64-19.11.0.0.0dbru.zip
$ unzip instantclient-odbc-linux.x64-19.11.0.0.0dbru.zip
$ unzip instantclient-sqlplus-linux.x64-19.11.0.0.0dbru.zip
$ unzip instantclient-tools-linux.x64-19.11.0.0.0dbru.zip
・共有ライブラリパスの設定
$ sudo sh -c "echo /opt/oracle/instantclient_19_11 > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig
・環境変数の設定
~/.bash_profileに以下を追加
ORACLE_HOME=/opt/oracle/instantclient_19_11
PATH=$PATH:$ORACLE_HOME ※PATHの追加は環境に合わせて編集
export TNS_ADMIN=/opt/oracle/instantclient_19_11/network/admin
export NLS_LANG=Japanese_Japan.AL32UTF8 ※ 環境にあわせて編集
ADBへの接続
ADBのClient Credentials (Wallet)をダウンロード
上記ファイルをunzipして、以下のファイルを$TNS_ADMIN配下にコピー
sqlnet.ora tnsnames.ora cwallet.sso
コピー後のファイルの状態
$ ls $TNS_ADMIN
cwallet.sso README sqlnet.ora tnsnames.ora
ADBへの接続確認
$ sqlplus admin/WelCome123#123#@ADW0801_high
$ sqlplus admin/WelCome123#123#@adw0801_high
SQL*Plus: Release 19.0.0.0.0 - Production on 木 7月 15 22:42:29 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
最終正常ログイン時間: 木 7月 15 2021 22:37:15 +00:00
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.5.0.0.0
に接続されました。
SQL> select BANNER from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> SELECT count(*) from sh.sales;
COUNT(*)
----------
918843
ODBC Driver Manager(unixODBC)のインストール
・関連するファイルのダウンロード&Install
yumが使える場合
sudo yum -y install unixODBC
使えない場合
$ mkdir hoge && cd hoge
$ curl -L -O www.unixodbc.org/unixODBC-2.3.9.tar.gz
$ tar zxvf unixODBC-2.3.9.tar.gz
$ cd unixODBC-2.3.9
$ ./configure
$ make
$ sudo make install
ODBCドライバの登録
ODBCドライバの確認
$ odbcinst -j
unixODBC 2.3.9
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /home/oracle/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
ODBCドライバの設定
Instant Client ODBCツールの以下コマンドを使って設定
odbc_update_ini.sh <ODBCDM_Home> [<Install_Location> <Driver_Name> <DSN> <ODBCINI>]
$ cd $ORACLE_HOME
$ sudo ./odbc_update_ini.sh /usr/local /opt/oracle/instantclient_19_11 "" ADW /usr/local/etc/odbc.ini
odbc_update_ini.shによって構成された設定内容の確認
$ cat /usr/local/etc/odbcinst.ini
[Oracle 19 ODBC driver]
Description = Oracle ODBC driver for Oracle 19
Driver = /opt/oracle/instantclient_19_11/libsqora.so.19.1
Setup =
FileUsage =
CPTimeout =
CPReuse =
$ cat /usr/local/etc/odbcinst.ini
[Oracle 19 ODBC driver]
Description = Oracle ODBC driver for Oracle 19
Driver = /opt/oracle/instantclient_19_11/libsqora.so.19.1
Setup =
FileUsage =
CPTimeout =
CPReuse =
[oracle@oc-cent08 instantclient_19_11]$ cat /usr/local/etc/odbc.ini
[ADW]
AggregateSQLType = FLOAT
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CacheBufferSize = 20
CloseCursor = F
DisableDPM = F
DisableMTS = T
DisableRULEHint = T
Driver = Oracle 19 ODBC driver
DSN = ADW
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
LobPrefetchSize = 8192
Lobs = T
Longs = T
MaxLargeData = 0
MaxTokenSize = 8192
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName =
SQLGetData extensions = F
SQLTranslateErrors = F
StatementCache = F
Translation DLL =
Translation Option = 0
UseOCIDescribeAny = F
UserID =
odbc.iniの編集
ServerNameとUserIDを編集
- ServerName : TNSNAMES.oraに登録したADBへの接続名
- UserID:ADB上のユーザ
- Password:ADB上のユーザのパスワード
以下の例は、ServerName:adw0801_high, UserID=adminの場合を記載
$ sudo vim /usr/local/etc/odbc.ini
(以下内容に変更)
ServerName = adw0801_high
UserID = ADMIN
■ 接続確認
isqlでの接続確認
※ 以下内容が、sqlplusで実行した結果と同じとなることを確認
$ isql ADW admin/WelCome123#123#
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select BANNER from v$version;
+---------------------------------------------------------------------------------+
| BANNER |
+---------------------------------------------------------------------------------+
| Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production |
+---------------------------------------------------------------------------------+
SQLRowCount returns -1
1 rows fetched
SQL> SELECT count(*) from sh.sales;
+-----------------------------------------+
| COUNT(*) |
+-----------------------------------------+
| 918843 |
+-----------------------------------------+
SQLRowCount returns -1
1 rows fetched
■ 補足情報
DataPumpの接続確認
expdp userid=admin/xxxxxxx#123#@adw0801_high \
tables=sh.sales \
directory=DATA_PUMP_DIR \
dumpfile=DATA_PUMP_DIR:expdp.dmp \
logfile=DATA_PUMP_DIR:expdp.log
Export: Release 19.0.0.0.0 - Production on 木 7月 15 22:53:17 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
接続先: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
"ADMIN"."SYS_EXPORT_TABLE_01"を起動しています: userid=admin/********@adw0801_high tables=sh.sales directory=DATA_PUMP_DIR dumpfile=DATA_PUMP_DIR:expdp.dmp logfile=DATA_PUMP_DIR:expdp.log
オブジェクト型TABLE_EXPORT/TABLE/TABLE_DATAの処理中です
オブジェクト型TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICSの処理中です
オブジェクト型TABLE_EXPORT/TABLE/STATISTICS/MARKERの処理中です
オブジェクト型TABLE_EXPORT/TABLE/TABLEの処理中です
オブジェクト型TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANTの処理中です
オブジェクト型TABLE_EXPORT/TABLE/COMMENTの処理中です
オブジェクト型TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINTの処理中です
. . "SH"."SALES" 29.62 MB 918843行がエクスポートされました
マスター表"ADMIN"."SYS_EXPORT_TABLE_01"は正常にロード/アンロードされました
******************************************************************************
ADMIN.SYS_EXPORT_TABLE_01に設定されたダンプ・ファイルは次のとおりです:
/u03/dbfs/C67BFB213B184F65E0530518000A3C4B/data/dpdump/expdp.dmp
ジョブ"ADMIN"."SYS_EXPORT_TABLE_01"が木 7月 15 22:53:58 2021 elapsed 0 00:00:36で正常に完了しました
SQL Loaderでの接続確認
・Loadするファイル
"7839","KING","11/17/1981","5000","10"
"7698","BLAKE","05/01/1981","2850","30"
"7782","CLARK","06/09/1981","2450","10"
"7566","JONES","04/02/1981","2975","20"
"7788","SCOTT","12/09/1982","3000","20"
・テスト用テーブル作成
CREATE TABLE "EMPLOYEES"
( "EMP_ID" VARCHAR2(100 BYTE),
"NAME" VARCHAR2(100 BYTE) ,
"HIRE_DATE" VARCHAR2(100 BYTE) ,
"SALARY" VARCHAR2(100 BYTE),
"DEPT_ID" VARCHAR2(100 BYTE)
) ;
ALTER TABLE "EMPLOYEES" ADD CONSTRAINT "EMP_EMP_ID_PK" PRIMARY KEY ("EMP_ID")
USING INDEX ENABLE;
・CSVファイルの作成
$ cat << EOF > emp.csv
"7839","KING","11/17/1981","5000","10"
"7698","BLAKE","05/01/1981","2850","30"
"7782","CLARK","06/09/1981","2450","10"
"7566","JONES","04/02/1981","2975","20"
"7788","SCOTT","12/09/1982","3000","20"
EOF
・コントールファイルの作成
$ cat << EOF > emp.ctl
LOAD DATA
INFILE '/home/oracle/tmp/emp.csv'
INTO TABLE EMPLOYEES
APPEND
FIELDS TERMINATED BY ','
(EMP_ID,NAME,HIRE_DATE,SALARY,DEPT_ID)
EOF
・Loadの実行
$ sqlldr admin/xxxxxxxx@adw0801_high control=/home/oracle/tmp/emp.ctl
CONTROL=/home/oracle/tmp/emp.ctl
SQL*Loader: Release 19.0.0.0.0 - Production on 木 7月 15 23:33:01 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2021, Oracle and/or its affiliates. All rights reserved.
使用パス: 従来型
コミット・ポイントに達しました - 論理レコード件数5
表EMPLOYEES:
5 行は正常にロードされました。
確認するログ・ファイル:
emp.log
ロードの詳細を参照してください。
■ 参考
Documentations
- Database Client Installation Guide for Linux
- Oracle Instant Client ODBCインストール・ノート
- ADB : Prepare for Oracle Call Interface (OCI), ODBC, and JDBC OCI Connections
- ADB : Connect with SQL*Plus
Download
MOS Notes
- How to Configure the Unix ODBC Driver Manager (64-bit) on Linux x86-64 (Doc ID 742548.1)
- How to Setup and Verify the Oracle ODBC Driver on Linux (Doc ID 404041.1)
- Client / Server Interoperability Support Matrix for Different Oracle Versions (Doc ID 207303.1)