使用可公開存取之非 Oracle 資料庫的客戶管理異質連線建立資料庫連結
您可以使用 DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK,從專用 Exadata 基礎架構上的自治式 AI 資料庫建立資料庫連結,該資料庫位於公用端點上的 Oracle Database Gateway,以存取非 Oracle 資料庫。
Oracle Database Gateway 是專為存取特定非 Oracle 系統而設計的閘道。使用 Oracle Database Gateway,您無需知道資料的位置或資料的儲存方式,即可存取分散式資料庫系統中任何位置的資料。在搭配 Oracle Database Gateway 的 Autonomous AI Database 上使用資料庫連結,可支援異質環境,無需自訂應用程式以存取來自非 Oracle 系統的資料。
注意:只有 19c 和 23.6 和更新版本的 19c 和 23.6 和更新的版本才支援使用客戶管理的異質連線至可公開存取的非 Oracle 資料庫建立資料庫連結。
必備條件
若要在公用端點上使用來自自治式 AI 資料庫執行處理的資料庫連結,請執行下列作業:
-
設定 Oracle Database Gateway 以存取非 Oracle 資料庫。請參閱 Oracle Database 19c Database Heterogeneous Connectivity User's Guide 中的 Oracle Database Gateways 或 Oracle Database 26ai Database Heterogeneous Connectivity User's Guide 以瞭解詳細資訊。
視您要連線的資料庫而定,您可以參閱相應的 Installation and Configuration Guide 和 Gateway User's Guide。
例如,若為 Oracle Database Gateway for SQL Server,請參閱:
-
Oracle Database 19c Installation and Configuration Guide for Microsoft Windows 或 Oracle Database 26ai Installation and Configuration Guide for Microsoft Windows 中的 Installing and Configuring Oracle Database Gateway for SQL Server
-
Oracle Database 19c User's Guide 或 Oracle Database 26ai User's Guide 中的 Introduction to the Oracle Database Gateway for SQL Server 。
-
Oracle Database 19c Installation and Configuration Guide for Microsoft Windows 或 Oracle Database 26ai Installation and Configuration Guide for Microsoft Windows 中的 Configure Oracle Net for the Gateway 。
-
-
設定 Oracle Net Listener 處理 Oracle Database Gateway 上的內送要求。
-
在 Oracle Database Gateway 上建立自行簽署的公事包。
-
將目標閘道設定為使用 TCP/IP 與 SSL (TCPS) 認證。請參閱 Oracle Database 19c Security Guide 中的 Configuring Transport Layer Security Authentication 或 Oracle Database 26ai Security Guide ,瞭解詳細資訊。
程序
使用 DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK 建立從公用端點上的自治式 AI 資料庫執行處理連至 Oracle Database Gateway 的資料庫連結,以存取非 Oracle 資料庫。
若要在公用端點上建立從自治式 AI 資料庫執行處理連至目標閘道的資料庫連結:
-
將包含 Oracle Database Gateway 之憑證的目標閘道自行簽署公事包 (例如 cwallet.sso) 複製到物件存放區。
注意:公事包檔案以及資料庫使用者 ID 和密碼可讓您存取目標閘道提供的資料。將錢包檔案存放在安全的位置 。只有授權的使用者才能共用公事包檔案。
-
建立證明資料以存取您儲存 cwallet.sso 的「物件存放區」。如需有關不同物件儲存服務之使用者名稱和密碼參數的資訊,請參閱 CREATE_CREDENTIAL 程序。
-
在「自治式 AI 資料庫」上建立公事包檔案
cwallet.sso的目錄。舉例而言:
CREATE DIRECTORY dblink_wallet_dir AS 'directory_path_of_your_choice';如需有關建立目錄的資訊,請參閱在 Autonomous AI 資料庫中建立目錄。
-
使用
DBMS_CLOUD.GET_OBJECT將目標閘道自行簽署的公事包上傳至您在上一個步驟DBLINK_WALLET_DIR中建立的目錄。舉例而言:
BEGIN DBMS_CLOUD.GET_OBJECT( credential_name => 'DEF_CRED_NAME', object_uri => 'https://objectstorage.us-phoenix-1.oraclecloud.com/n/namespace-string/b/bucketname/o/cwallet.sso', directory_name => 'DBLINK_WALLET_DIR' ); END;在此範例中,
namespace-string是 Oracle Cloud Infrastructure 物件儲存命名空間,而bucketname是儲存桶名稱。請參閱瞭解物件儲存命名空間以瞭解詳細資訊。您在此步驟中使用的
credential_name是「物件存放區」的證明資料。下一步是建立用以存取目標閘道的證明資料。請參閱 GET_OBJECT 程序和函數以瞭解詳細資訊。
-
在自治式 AI 資料庫上,建立用以存取目標資料庫的證明資料。您以
DBMS_CLOUD.CREATE_CREDENTIAL指定的使用者名稱和密碼是資料庫連結內所使用之目標資料庫的證明資料 (可透過 Oracle Database Gateway 存取目標資料庫的位置)。舉例而言:
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'DB_LINK_CRED', username => 'NICK', password => 'password' ); END;/必須提供
credential_name參數。username參數中的字元必須全部都是大寫字母。此作業會以加密格式將證明資料儲存在資料庫中。您可以為證明資料名稱使用任何名稱。
-
使用
DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK建立目標閘道的資料庫連結。舉例而言:
BEGIN DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK( db_link_name => 'SALESLINK', hostname => 'example.com', port => '1522', service_name => 'example_service_name', ssl_server_cert_dn => 'ssl_server_cert_dn', credential_name => 'DB_LINK_CRED', directory_name => 'DBLINK_WALLET_DIR', gateway_link => TRUE ); END;/ADMIN 以外的使用者需要執行
DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK的權限。請參閱 CREATE_DATABASE_LINK 程序以瞭解詳細資訊。
-
請使用您建立的資料庫連結來存取目標閘道上的資料。
舉例而言:
SELECT * FROM employees@SALESLINK;
對於您在步驟 5 中建立的證明資料,Oracle Database Gateway 證明資料,如果目標使用者的密碼變更,您可以更新包含目標使用者證明資料的證明資料,如下所示:
BEGIN
DBMS_CLOUD.UPDATE_CREDENTIAL(
credential_name =>'DB_LINK_CRED',
attribute =>'PASSWORD',
value=>'password'
);
END;
/
其中密碼是新密碼。
此作業之後,使用此證明資料的現有資料庫連結會繼續運作,而不需要刪除並重新建立資料庫連結。
請參閱 UPDATE_CREDENTIAL 程序以瞭解詳細資訊。
請參閱如何使用 Oracle Database Gateway 從 Autonomous AI 資料庫存取非 Oracle 資料庫,以取得建立 Oracle Database Gateway 的資料庫連結以存取 Microsoft SQL Server 資料庫的範例。
備註:雖然上述部落格探討 Autonomous AI Database Serverless 的脈絡,但該部落格中的所有內容也適用於 Dedicated Exadata Infrastructure 上的 Autonomous AI Database。