【问题标题】:Downloading oracle RDS table data to a local database下载oracle RDS表数据到本地数据库
【发布时间】:2019-07-12 04:24:33
【问题描述】:

我有一个 Amazon Oracle RDS 数据库。我想导出 RDS 表并将其导入本地数据库。最重要的是它包含一个 NCLOB 列。本地系统是运行Cygwin的Win10。

我运行 expdp 来捕获数据:

$ expdp xlat@int_rds/*****tables=TEXT_POOL_XLAT file=int_TEXT_POOL_XLAT.expdp

Export: Release 11.2.0.1.0 - Production on Mon Feb 18 11:37:30 2019

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

Connected to: Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
Legacy Mode Active due to the following parameters:
Legacy Mode Parameter: "file=int_TEXT_POOL_XLAT.expdp" Location: Command Line, Replaced with: "dumpfile=int_TEXT_POOL_XLAT.expdp"
Legacy Mode has set reuse_dumpfiles=true parameter.
Legacy Mode has set nologfile=true parameter.
Starting "XLAT"."SYS_EXPORT_TABLE_01":  xlat/********@int_rds tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp reuse_dumpfiles=true nologfile=true
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 51.68 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "XLAT"."TEXT_POOL_XLAT"                     32.50 MB  137850 rows
Master table "XLAT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for XLAT.SYS_EXPORT_TABLE_01 is:
  /rdsdbdata/datapump/int_TEXT_POOL_XLAT.expdp
Job "XLAT"."SYS_EXPORT_TABLE_01" successfully completed at Mon Feb 18 17:37:29 2019 elapsed 0 00:00:04

到目前为止一切顺利。 expdp 将文件转储到 Oracle DATA_PUMP_DIR 中,我使用脚本通过 sqlplus 命令下载数据:

sqlplus -s $DBusername/$DBpassword@$database >/dev/null <<EOF 
set colsep ,
set pagesize 0
set trimspool on
set headsep off
set linesize 8000
set termout off
SET FEEDBACK OFF
spool $filename $append
select * from table (rdsadmin.rds_file_util.read_text_file(p_directory => 'DATA_PUMP_DIR', p_filename  => '$DPfilename'));
quit
EOF

数据被下载。但是当我运行 impdp 时,我得到:

$ impdp xlat/f0nature1931@local tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp directory='DATA_PUMP_DIR'

Import: Release 11.2.0.1.0 - Production on Mon Feb 18 11:58:32 2019

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

Connected to: Personal Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31619: invalid dump file "C:\app\waynej/admin/orcl/dpdump/int_TEXT_POOL_XLAT.expdp"

我错过了什么吗?我认为这不是 CR/LF 问题,因为脚本下载时没有任何翻译。

提前致谢。

【问题讨论】:

    标签: oracle impdp expdp


    【解决方案1】:

    RDS 程序rdsadmin.rds_file_util.read_text_file读取文本文件。 EXPDP DUMP 文件不是文本文件,它是二进制文件。

    RDS 实例的文件访问被禁止。只能通过db_link访问DATA_PUMP_DIR目录,使用DBMS_FILE_TRANSFER包。

    1. 在 RDS DB 和本地之间的 RDS 实例上创建数据库链接 甲骨文。
    2. 将转储文件从 RDS 实例复制到本地 Oracle DB 使用 DBMS_FILE_TRANSFER.PUT_FILE 通过数据库链接
    3. 将转储文件导入本地数据库 impdp xlat/f0nature1931@local tables=TEXT_POOL_XLAT dumpfile=int_TEXT_POOL_XLAT.expdp directory='DATA_PUMP_DIR'

    如果您没有机会在本地数据库和 RDS Oracle 之间建立链接,您可以通过另外两种方式导出数据。

    1 您可以使用本地 PC 上的旧 exp 实用程序导出数据,该实用程序还创建导出文件 .dmp,但格式不同。该格式与 impdp expdp 不兼容。 exp imp 实用程序可以作为客户端-服务器通过 SQL*NET 网络连接到目标数据库。此实用程序已过时且性能较差。与运行实用程序 expdp 时一样,不会在服务器上创建 dmp 文件。 dmp 文件写在运行实用程序 exp 的一侧(服务器或客户端)

    $ORACLE_HOME/bin/exp parfile=parfile_exp_full FILE=export.dmp LOG=export.log
    

    然后使用 imp 将数据导入到本地 Oracle 实例。

    $ORACLE_HOME/bin/imp parfile=parfile_imp_full FILE=export.dmp LOG=import.log
    

    2

    您可以使用 sqlplus 将数据导出到 CSV 文件

    $ORACLE_HOME/bin/sqlplus -s user/pass@rds_amazon  @csv2.sql.
    
    more csv2.sql 
    
    set heading off
    set termout OFF
    SET FEEDBACK OFF
    SET TAB OFF
    set pause off
    set verify off
    SET UNDERLINE OFF
    set trimspool on
    set echo off
    set linesize 1000
    set pagesize 0
    set wrap off
    spool test2.csv
    select code||','||name||','||code_rail from alexs.all_station;
    spool off
    exit;
    

    然后使用实用程序 sqlldr 或 SQL Developer 将数据导入本地 Oracle 实例。

    SQL Developer for importing from Excel

    【讨论】:

    • 我最终做了 exp/imp。花了6个小时。我将在未来研究解决方案 1。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多