Oracle DBのデータをOCI Object Storageへ直接エクスポートする方法

Database

初めに

前回の記事では、OCI Object Storage から Oracle DB 19c/21c へデータをロードする方法をご紹介しました。
オブジェクト・ストレージからOracle DB 19c/21cにデータを導入する

その記事では、主に以下の3点について説明しました:

  1. Oracle DB に DBMS_CLOUD をインストールする方法
  2. DBMS_CLOUD を用いて、OCI Object Storage のCSVファイルを Oracle DB へロードする方法
  3. DBMS_CLOUD を用いて、OCI Object Storage のData Pumpファイルを一度ローカルにコピーした後、Oracle DB へインポートする方法

今回は、Data Pumpファイルを ローカルへのコピーを必要とせず、Oracle DB から直接 OCI Object Storage へエクスポートする方法をご紹介します(インポートの例も併せて記載します)。
Export Oracle DB to OCI Object Storage

検証環境
DBバージョン:21c Standard Edition (シングル・ノード)
DBシステム・バージョン:21.4
リージョン:東京

この例では、OCI Base Database 21c (VM)インスタンスを使用していますが、本手順はは On-P DB と Cloud DB の両方に適用できます。

Oracle DB (On-P/Cloud) の場合、DBMS_CLOUDはデフォルトでインストールされていないため、使用前にインストールと設定が必要です。

一方、Autonomous DBの場合、DBMS_CLOUDは既にインストールされています。そのため、クレデンシャルの作成から手順を開始できます。詳細は、以下の手順をご参照ください。
Autonomous DBからOCIオブジェクト・ストレージへデータ・ポンプをエクスポートする手順

比較項目Oracle DB 19cOracle DB 21cAutonomous DB
DBバージョン19.1321.419c
DBMS_CLOUDはインストール済
であるか
NoNoYes
直接にOCIオブジェクト・
ストレージにエクスポート
NoYesYes

注意
1. Oracle DB 19.13 以下の場合、現時点(2022年1月)まで、まだ Data PumpファイルをOOS (OCI Object Storage)に直接エクスポートすることはできません。Data Pumpファイルをローカル・ディレクトリにエクスポートしてから、OOSにアップロードする必要があります。
2. 上記の情報は、このブログの投稿日である2022年1月現在のものです。

STEP1 ~ STEP9 以前の記事の手順と同様

詳細について、次をご確認いただければと思います。
オブジェクト・ストレージからOracle DB 19c/21cにデータを導入する

STEP10 - エクスポートのための準備

ディレクトリの作成
DUMPファイル用のディレクトリを作成し、権限を対象ユーザ(USER01)に付与します。
(/u01/app/oracle/dmpを事前に作成しておきます。)

SQL> show user;
USER is "SYSTEM"
SQL> CREATE OR REPLACE DIRECTORY TEST_DIR AS '/u01/app/oracle/dmp/';

Directory created.

SQL> GRANT READ, WRITE ON DIRECTORY TEST_DIR TO USER01;

Grant succeeded.

SQL>

テスト用テーブルの準備

SQL> desc CHANNELS;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 CHANNEL_ID                                         CHAR(1)
 CHANNEL_DESC                                       VARCHAR2(20)
 CHANNEL_CLASS                                      VARCHAR2(20)

SQL> select * from CHANNELS;

C CHANNEL_DESC         CHANNEL_CLASS
- -------------------- --------------------
S Direct Sales         Direct
T Tele Sales           Direct
C Catalog              Indirect
I Internet             Indirect
P Partners             Others

SQL> select count(*) from CHANNELS;

  COUNT(*)
----------
         5

エクスポートの既存問題
Oracle DB 21.3以降の場合、expdpを使用して On-P/DBaaS からOCI Object Storage にエクスポートすると、次の問題が発生します。

[oracle@db21c dmp]$ expdp USER01/Your_Password@DB_Hostname_or_IP/db21cse_pdb1.publicsubnet1.vcn1.oraclevcn.com \
>      credential=TEST_CRED \
>      tables=CHANNELS \
>      dumpfile='https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp' \
>      logfile=export.log \
>      directory=TEST_DIR

Export: Release 21.0.0.0.0 - Production on Tue Jan 25 01:38:46 2022
Version 21.1.0.0.0

Copyright (c) 1982, 2020, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31641: unable to create dump file "https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp"
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1


[oracle@db21c dmp]$

Oracleは、この問題を解決するために、次のMOSドキュメントを提供しています。 (アカウントは必要)
DATA PUMP EXPORT TO OCI OBJECT STORAGE FAILED ORA-39001 ORA-39000 ORA-31641 (Doc ID 2806178.1)

原因
オブジェクト・ストア ODM ライブラリは、デフォルトでは有効になっていません。

DBアラート・ファイルから、メッセージを確認してください。
DBアラート・ファイルの保存場所:
/u01/app/oracle/diag/rdbms/<Database_Unique_Name>/<Database_Name>/trace
例: /u01/app/oracle/diag/rdbms/db21cse_nrt12h/DB21cSE/trace

Database Unique Name(一意のデータベース名)」と「Database Name(データベース名)」の情報は、OCIコンソールから取得できます。
Check Database Name and Database Unique Name

[oracle@db21c ~]$ cd /u01/app/oracle/diag/rdbms/db21cse_nrt12h/DB21cSE/trace
[oracle@db21c trace]$ grep -i ODM alert_DB21cSE.log
......
Oracle instance running with ODM in SGA: FSDirect ODM Library Version 1.0

解決方法
次のコマンドを実行して、オブジェクト・ストアODMライブラリを有効にします。

dbshut $ORACLE_HOME  
cd $ORACLE_HOME/rdbms/lib  
make -f ins_rdbms.mk opc_on  
dbstart $ORACLE_HOME

実行結果:

[oracle@db21c trace]$ dbshut $ORACLE_HOME
[oracle@db21c trace]$ cd $ORACLE_HOME/rdbms/lib
[oracle@db21c lib]$ make -f ins_rdbms.mk opc_on
rm -f /u01/app/oracle/product/21.0.0.0/dbhome_1/rdbms/lib/odm/libopcodm.so; \
    cp /u01/app/oracle/product/21.0.0.0/dbhome_1/lib/libopcodm.so /u01/app/oracle/product/21.0.0.0/dbhome_1/rdbms/lib/odm/libopcodm.so
[oracle@db21c lib]$ dbstart $ORACLE_HOME
[oracle@db21c lib]$

DBアラート・ファイルのメッセージをもう一度確認してください。

[oracle@db21c lib]$ cd /u01/app/oracle/diag/rdbms/db21cse_nrt12h/DB21cSE/trace
[oracle@db21c trace]$ grep -i ODM alert_DB21cSE.log
......
Oracle instance running with ODM in SGA: Object Store ODM Library Version 7.0

これで、エクスポートの再実行ができます。

STEP11 - Oracle DB から OCI Object Storage へデータをエクスポート

エクスポート用コマンド

expdp user/password@<connection_string> \
  credential=<credential_name> \
  tables=table_name \
  dumpfile=https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/<bucketname>/o/ \
  export_file_name.dmp \
  logfile=export.log \
  directory=data_pump_dir

実行結果:

[oracle@db21c dmp]$ expdp USER01/Your_Password@<DB_Hostname_or_IP>/db21cse_pdb1.publicsubnet1.vcn1.oraclevcn.com \
>      credential=TEST_CRED \
>      tables=CHANNELS \
>      dumpfile='https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp' \
>      logfile=export.log \
>      directory=TEST_DIR

Export: Release 21.0.0.0.0 - Production on Wed Jan 26 03:51:19 2022
Version 21.1.0.0.0

Copyright (c) 1982, 2020, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
Starting "USER01"."SYS_EXPORT_TABLE_01":  USER01/********@<DB_Hostname_or_IP>/db21cse_pdb1.publicsubnet1.vcn1.oraclevcn.com credential=TEST_CRED tables=CHANNELS dumpfile=https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp logfile=export.log directory=TEST_DIR
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "USER01"."CHANNELS"                         6.031 KB       5 rows
ORA-39173: Encrypted data has been stored unencrypted in dump file set.
Master table "USER01"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for USER01.SYS_EXPORT_TABLE_01 is:
  https://swiftobjectstorage.ap-tokyo-1.oraclecloud.com/v1/<ObjectStorageNameSpace>/Bucket1/channels.dmp
Job "USER01"."SYS_EXPORT_TABLE_01" successfully completed at Wed Jan 26 03:51:52 2022 elapsed 0 00:00:27

[oracle@db21c dmp]$

今回エクスポートは正常に動作しています。

OCIコンソールからData Pumpファイルを確認
以下のように2つファイルがバケットに新規作成されました。
Check data pump file

DB 19cからのエクスポート

上記と同じコマンドを使って Oracle DB 19c (19.13以下) からエクスポートしようとすると、次のようなエラーが発生します。そのため、現時点(2022年1月)まで、Oracle 19c から OCI Object Storage に直接エクスポートすることはできません。テーブルをローカル・ディレクトリにエクスポートしてから、Data Pumpファイルをオブジェクト・ストレージにアップロードする必要があります。

Connected to: Oracle Database 19c EE High Perf Release 19.0.0.0.0 - Production
ORA-39001: invalid argument value
ORA-39208: Parameter KU$_FILE_TYPE_URIDUMP_FILE is invalid for EXPORT jobs.

STEP12 - OCI Object Storage から Oracle DB へデータをインポート(オプション)

このステップはオプションです。エクスポートされたData Pumpファイルが正常にインポートできることを確認します。

インポート用コマンド

impdp user/password@<connection_string> \
  credential=credential_name \
  tables=table_name \
  table_exists_action=[SKIP|APPEND|TRUNCATE|REPLACE] \
  dumpfile=https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/bucketname/o/ \
  export_file_name.dmp \
  logfile=import.log

実行結果:

[oracle@db21c ~]$ impdp USER01/Your_Password#@<DB_Hostname_or_IP>/db21cse_pdb1.publicsubnet1.vcn1.oraclevcn.com \
>      credential=TEST_CRED \
>      tables=CHANNELS \
>      table_exists_action=TRUNCATE \
>      dumpfile='https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp' \
>      logfile=import.log

Import: Release 21.0.0.0.0 - Production on Wed Jan 26 06:12:40 2022
Version 21.1.0.0.0

Copyright (c) 1982, 2020, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 21c Standard Edition 2 Release 21.0.0.0.0 - Production
Master table "USER01"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "USER01"."SYS_IMPORT_TABLE_01":  USER01/********@<DB_Hostname_or_IP>/db21cse_pdb1.publicsubnet1.vcn1.oraclevcn.com credential=TEST_CRED tables=CHANNELS table_exists_action=TRUNCATE dumpfile=https://objectstorage.ap-tokyo-1.oraclecloud.com/n/<ObjectStorageNameSpace>/b/Bucket1/o/channels.dmp logfile=import.log
Processing object type TABLE_EXPORT/TABLE/TABLE
Table "USER01"."CHANNELS" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "USER01"."CHANNELS"                         6.031 KB       5 rows
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER
Job "USER01"."SYS_IMPORT_TABLE_01" successfully completed at Wed Jan 26 06:12:47 2022 elapsed 0 00:00:04

[oracle@db21c ~]$

インポート後、テーブルの内容を確認します。

SQL> select * from channels;

C CHANNEL_DESC         CHANNEL_CLASS
- -------------------- --------------------
S Direct Sales         Direct
T Tele Sales           Direct
C Catalog              Indirect
I Internet             Indirect
P Partners             Others

以上

タイトルとURLをコピーしました