注意:

使用 Oracle Data Pump 将数据迁移到 Oracle Database@Google Cloud

简介

Oracle Database@Google Cloud 是一项 Oracle Cloud Database 服务,可在 Google Cloud 环境中运行 Oracle Database 工作负载。基于 Oracle 的优秀数据库服务(如 Oracle Exadata Database Service 和 Oracle Autonomous Database)构建,您可以使用 Oracle Database 23ai AI Vector Search 和 Google Vertex AI 等功能快速开发和现代化应用。

通过本机集成,您可以在基于 Oracle Cloud Infrastructure (OCI) Exadata 硬件运行的 Google Cloud 数据中心中部署 Oracle 数据库服务,以尽可能减少延迟。工作负载位于 Google Cloud 中,两个服务使用的 Exadata 系统都部署在 Google Cloud 数据中心中。您可以充分利用 Oracle 和 Google Cloud,包括性能和监视工具、开发人员工具、分析等。

Oracle Data Pump 在用户管理的 Oracle 数据库和 Oracle Autonomous Database 之间提供非常快速的批量数据和元数据移动。

通过 Oracle Data Pump Import,您可以从位于 OCI Object Storage 中的 Oracle Data Pump 文件导入数据。您可以将数据保存到 Google Cloud Storage 存储桶,并使用 Oracle Data Pump 将数据加载到 Oracle Autonomous Database。

本教程将引导您完成使用 Oracle Data Pump Import 迁移到 Oracle Database@Google Cloud 的示例应用程序方案的步骤。

目标

作为数据库管理员或用户:

先决条件

任务 1:为您的用户帐户生成访问密钥

  1. 登录到 Google Cloud Console,转到云存储,然后单击设置

    云存储设置

  2. 设置页中,单击 INTEROPERABILITY 。在用户帐户的访问密钥下,单击创建密钥

    云存储设置

    云存储设置

    记下 Access keySecret

任务 2:将转储文件上载到 Google Cloud Storage 存储桶

在此任务中,将要迁移到 Oracle Database@Google Cloud 的方案的数据库导出转储文件上载到 Google Cloud Storage 桶。如果此时没有转储文件并且正在测试迁移,则可以从以下位置下载转储文件:HR.dmp

  1. 转到 Google Cloud Console,导航到 Cloud StorageBuckets ,然后单击 CREATE 创建 Google Cloud Storage 桶。对于此示例,我们将存储桶命名为 gcpdatapump

  2. 单击 gcpdatapump 存储桶并上载转储文件。

任务 3:在目标 Oracle Autonomous Database 中设置用户身份证明

现在,我们有访问密钥和密钥,让我们设置目标数据库以从 Google Cloud Storage 读取并导入数据。

在这里,我们将使用 SQLcl 演示设置 Google Cloud Storage 凭据所需的步骤。

  1. 从此处下载 SQLcl 并安装 Google Cloud Compute Engine VM 实例: sqlcl-24.3.2.330.1718.zip

  2. 运行以下命令以解压缩文件。

    wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-24.3.2.330.1718.zip
    unzip sqlcl-24.3.2.330.1718.zip
    
  3. 在 Google Cloud Console 中,转到 Autonomous Database 页面,然后单击预配的自治数据库。

    云存储设置

  4. 转到 Autonomous Database Details(自治数据库详细信息)页面,单击 CONNECTIONS(连接),然后记下 TNS 名称连接字符串

    云存储设置 云存储设置

  5. sqlcl/bin 下创建一个名为 tnsnames.ora 的文件,并将 TNS_ADMIN 变量设置为当前工作目录。使用连接字符串或通过设置 tnsnames 路径来连接到 Oracle Autonomous Database。

    • 设置 tnsnames 路径并连接到数据库。

      cd sqlcl/bin
      $ cat tnsnames.ora 
      adbgcp_high=(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=mahfgbhj.adb.us-ashburn-1.oraclecloud.com))(connect_data=(service_name=gd443790554e91c_adbgcp_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))
      $ 
      export TNS_ADMIN=`pwd`
      ./sqlcl admin@adbgcp_high
      

    或者

    • 使用连接字符串进行设置。

      cd sqlcl/bin 
      ./sqlcl admin@"(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=mahfgbhj.adb.us-ashburn-1.oraclecloud.com))(connect_data=(service_name=gd443790554e91c_adbgcp_high.adb.oraclecloud.com))(security=(ssl_server_dn_match=no)))"
      
  6. 以管理员用户身份连接到自治数据库后,运行以下 PL/SQL 过程,将 username 替换为 Access key(访问密钥),将 password 替换为 Secret(密钥)

    set define off
    begin
    DBMS_CLOUD.CREATE_CREDENTIAL(
    credential_name => 'GOOGLE_CRED_NAME',
    username => 'Access_key',
    password => 'Secret'
    );
    END;
    /
    

    云存储设置

    确保从日志消息成功执行 PL/SQL 过程。

  7. 运行以下查询以测试对 Google Cloud Storage 的访问。

    SELECT * FROM DBMS_CLOUD.LIST_OBJECTS('GOOGLE_CRED_NAME', 'https://gcpdatapump.storage.googleapis.com/');
    

    此图显示执行上述步骤的结果。

任务 4:使用 impdp 实用程序从 Google Cloud Storage 存储桶导入数据

在同一 SQLcl 窗口中,运行以下数据泵导入命令。

datapump import -
-schemas HR -
-excludeexpr "IN ('PROCEDURE', 'PACKAGE')" -
-directory data_pump_dir -
-credential GOOGLE_CRED_NAME -
-remaptablespaces USERS=DATA -
-dumpuri https://gcpdatapump.storage.googleapis.com/HR.dmp -
-logfile testuser1.log

此图显示执行上述步骤的结果。

现在,已成功导入您的应用程序方案。

后续步骤

实施此解决方案时,您可以在两个云环境中部署资源:数据库资源位于 Google Cloud 中,而数据库管理控制层位于 Oracle Cloud Infrastructure (OCI) 中。这样,您可以在 Google Cloud 环境中部署 Oracle Database 产品,而 OCI 可维护管理功能。

Oracle Data Pump 可用于将数据从本地或其他云提供商迁移到 Oracle Database@Google Cloud。除了 Oracle Data Pump 之外,Oracle Zero Downtime Migration 还可用于将数据迁移到 Oracle Database@Google Cloud。

致谢

更多学习资源

浏览 docs.oracle.com/learn 上的其他实验室,或者访问 Oracle Learning YouTube 渠道上的更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 成为 Oracle Learning Explorer。

有关产品文档,请访问 Oracle 帮助中心