【问题标题】:Import Oracle dump on Amazon RDS在 Amazon RDS 上导入 Oracle 转储
【发布时间】:2018-01-09 17:02:42
【问题描述】:

我有来自 OracleDB 生产实例的转储文件,我需要将其导入到我们的新闻 RDS 实例中。

我按照http://d0.awsstatic.com/whitepapers/strategies-for-migrating-oracle-database-to-aws.pdf 的说明进行操作(来自 p23) 和http://www.connecteddba.com/howto/MigratetoRDS.html(大致相同)

文件在EC2实例上,我可以连接到RDS实例,用户有正确的权限。

我正确安装了 perl 库来运行脚本

$ perl -e 'use DBI; print $DBI::VERSION,"\n";'
1.633
$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";'
1.74

我已将变量配置为指向我的 RDS 信息 - 从 http://www.connecteddba.com/howto/MigratetoRDS.html 站点的测试连接中,它正确通过

$ perl test.pl
Got here without dying

但是在运行复制脚本时,它会失败并出现以下错误:

$ perl copy_to_rds.pl <myfile>.dmp
DBD::Oracle::db do warning: ORA-24344: success with compilation error (DBD SUCCESS_WITH_INFO: OCIStmtExecute) [for Statement "create or replace package perl_global as fhutl_file.file_type; end;"] at copy_to_rds.pl line 25.
DBD::Oracle::st execute failed: ORA-06550: Ligne 1, colonne 7 :
PLS-00905: object <myrdsuser>.PERL_GLOBAL is invalid
ORA-06550: Ligne 1, colonne 7 :
PL/SQL: Statement ignored (DBD ERROR: error possibly near <*> indicator at char 6 in 'BEGIN <*>perl_global.fh := utl_file.fopen(:dirname, :fname, 'wb', :chunk); END;') [for Statement "BEGIN perl_global.fh := utl_file.fopen(:dirname, :fname, 'wb', :chunk); END;" with ParamValues: :chunk=8192, :dirname='DATA_PUMP_DIR', :fname='<myfile>.dmp'] at copy_to_rds.pl line 30.
ORA-06550: Ligne 1, colonne 7 :
PLS-00905: object <myrdsuser>.PERL_GLOBAL is invalid
ORA-06550: Ligne 1, colonne 7 :
PL/SQL: Statement ignored (DBD ERROR: error possibly near <*> indicator at char 6 in 'BEGIN <*>perl_global.fh := utl_file.fopen(:dirname, :fname, 'wb', :chunk); END;')

脚本如下所示:

use DBI;
use warnings;
use strict;

# RDS instance info
my $RDS_PORT=1521;
my $RDS_HOST="<my rds instance>";
my $RDS_LOGIN="<myuser>/*******";
my $RDS_SID="<ORCL_LIKE>"; 

#The $ARGV[0] is a parameter you pass into the script
my $dirname = "DATA_PUMP_DIR";
my $fname = $ARGV[0];

my $data = "dummy";
my $chunk = 8192;

my $sql_open = "BEGIN perl_global.fh := utl_file.fopen(:dirname, :fname, 'wb', :chunk); END;";
my $sql_write = "BEGIN utl_file.put_raw(perl_global.fh, :data, true); END;";
my $sql_close = "BEGIN utl_file.fclose(perl_global.fh); END;";
my $sql_global = "create or replace package perl_global as fhutl_file.file_type; end;";

my $conn = DBI->connect('dbi:Oracle:host='.$RDS_HOST.';sid='.$RDS_SID.';port='.$RDS_PORT,$RDS_LOGIN, '') || die ( $DBI::errstr . "\n");

my $updated=$conn->do($sql_global);
my $stmt = $conn->prepare ($sql_open);
$stmt->bind_param_inout(":dirname", \$dirname, 12);
$stmt->bind_param_inout(":fname", \$fname, 12);
$stmt->bind_param_inout(":chunk", \$chunk, 4);
$stmt->execute() || die ( $DBI::errstr . "\n");

open (INF, $fname) || die "\nCan't open $fname for reading: $!\n";
binmode(INF);
$stmt = $conn->prepare ($sql_write);
my %attrib = ('ora_type','24');
my $val=1;
while ($val> 0) {
  $val = read (INF, $data, $chunk);
  $stmt->bind_param(":data", $data , \%attrib);
  $stmt->execute() || die ( $DBI::errstr . "\n") ; };
die "Problem copying: $!\n" if $!;
close INF || die "Can't close $fname: $!\n";
  $stmt = $conn->prepare ($sql_close);
$stmt->execute() || die ( $DBI::errstr . "\n") ;

【问题讨论】:

  • 你的代码是什么样的?
  • create or replace package perl_global as fhutl_file.file_type; end; 这没有使用正确的语法。
  • 语法应该是什么?我想念 \ 吗?我按照文档中的说明进行操作

标签: oracle perl amazon-web-services


【解决方案1】:

对于遇到同样问题的人来说,确实语法不正确,必须是

my $sql_global = "create or replace package perl_global as fh utl_file.file_type; end;";

链接上的脚本不正确,但在亚马逊的 pdf 文件中是正确的。

【讨论】:

  • 假设我有一个 data.dmp 文件。我把它放在 EC2 Windows 上。我可以使用 SQL Developer 从这个 EC2 连接到 Oracle RDS。但我不知道如何运行脚本。请告诉我好吗?
  • 您需要在 windows 上安装 perl 并从 perl 控制台或 windows 命令行运行它
  • 我在下面发布了我的脚本。它没有用。它说:无法识别的字符 \x93,由
  • 不要发布您的脚本作为答案 - 创建一个新问题并从新评论指向新帖子
猜你喜欢
  • 1970-01-01
  • 2018-04-23
  • 2016-06-28
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 2016-05-20
  • 1970-01-01
相关资源
最近更新 更多