正在下载 oracle RDS table 数据到本地数据库

Downloading oracle RDS table data to a local database

我有一个 Amazon Oracle RDS 数据库。我想导出 RDS table 并将其导入我的本地数据库。关键是它包含一个 NCLOB 列。本地系统是Win10 运行ning Cygwin.

我运行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 问题,因为脚本下载时没有任何翻译。

提前致谢。

RDS 程序 rdsadmin.rds_file_util.read_text_file 读取 一个文本文件。 EXPDP DUMP 文件不是文本文件,它是 binary 文件。

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

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

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

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