使用與可公開存取之非 Oracle 資料庫的客戶管理異質連線建立資料庫連結

Use DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK to create database links from an Autonomous AI Database on Dedicated Exadata Infrastructure that is on a public endpoint to an Oracle Database Gateway to access Non-Oracle databases.

Oracle Database Gateway 是專為存取特定非 Oracle 系統而設計的閘道。使用 Oracle Database Gateway,您無需知道資料的位置或資料的儲存方式,即可存取分散式資料庫系統中任何位置的資料。搭配 Oracle Database Gateway 在 Autonomous AI Database 上使用資料庫連結,可支援異質環境,無需自訂應用程式以存取來自非 Oracle 系統的資料。

附註:

只有 19c 和 23.6 和更新版本 (適用於 23ai) 的 19.25 和更新版本才支援使用客戶管理的異質連線建立資料庫連結,以連線至可公開存取的非 Oracle 資料庫。

必備條件

若要在公用端點上使用來自 Autonomous AI Database 執行處理的資料庫連結,請執行下列作業:

  1. 設定 Oracle Database Gateway 以存取非 Oracle 資料庫。請參閱 Oracle Database 19c Database Heterogeneous Connectivity User's Guide 中的 Oracle Database GatewaysOracle Database 26ai Database Heterogeneous Connectivity User's Guide 以瞭解詳細資訊。

    視您要連線的資料庫而定,您可以參閱相應的 Installation and Configuration Guide 和 Gateway User's Guide。

    例如,若為 Oracle Database Gateway for SQL Server,請參閱:

  2. 設定 Oracle Net Listener 處理 Oracle Database Gateway 上的內送要求。

  3. 在 Oracle Database Gateway 上建立自行簽署的公事包。

  4. 將目標閘道設定為使用 TCP/IP 與 SSL (TCPS) 認證。請參閱 Oracle Database 19c Security Guide 中的 Configuring Transport Layer Security AuthenticationOracle Database 26ai Security Guide ,瞭解詳細資訊。

程序

使用 DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK 建立從公用端點上的自治式 AI 資料庫執行處理至 Oracle Database Gateway 的資料庫連結,以存取非 Oracle 資料庫。

若要建立從公用端點上的 Autonomous AI Database 執行處理到目標閘道的資料庫連結:
  1. 將包含 Oracle Database Gateway 憑證的目標閘道自行簽署公事包 (例如 cwallet.sso) 複製到物件存放區。

    附註:

    公事包檔案以及資料庫使用者 ID 和密碼,可讓您透過目標閘道存取可用的資料。將公事包檔案儲存在安全位置。只與授權的使用者共用公事包檔案。
  2. 建立證明資料以存取儲存 cwallet.sso 的「物件存放區」。請參閱 CREATE_CREDENTIAL 程序,瞭解不同物件儲存服務的使用者名稱和密碼參數相關資訊。
  3. Autonomous AI Database 上為公事包檔案 cwallet.sso 建立目錄。
    舉例而言:
    CREATE DIRECTORY dblink_wallet_dir AS 'directory_path_of_your_choice';

    如需有關建立目錄的資訊,請參閱Autonomous AI Database 中建立目錄

  4. 使用 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-stringOracle Cloud Infrastructure 物件儲存命名空間,bucketname 是儲存桶名稱。如需詳細資訊,請參閱瞭解 Object Storage 命名空間

    您在此步驟中使用的 credential_name 是「物件存放區」的證明資料。在下一個步驟中,您會建立證明資料以存取目標閘道。

    請參閱 GET_OBJECT 程序和函數以瞭解詳細資訊。

  5. Autonomous AI Database 上,建立用以存取目標資料庫的證明資料。您以 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 參數中的字元必須全部為大寫字母。

    此作業會以加密格式將證明資料儲存在資料庫中。您可以使用任何證明資料名稱。

  6. 使用 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 程序

  7. 使用您建立的資料庫連結存取目標閘道上的資料。
    舉例而言:
    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 Database 存取非 Oracle 資料庫,以取得建立 Oracle Database Gateway 資料庫連結以存取 Microsoft SQL Server 資料庫的範例。

附註:

雖然上述部落格探討 Autonomous AI Database Serverless 的脈絡,但該部落格中的所有內容也適用於 Autonomous AI Database on Dedicated Exadata Infrastructure