单实例数据库迁移到rac环境(一)

简介:

从本节开始,将介绍下如何将单实例数据库迁移到rac环境。在生产环境中,随着业务和数据量的加大,这种需求和场景不可避免,一般来讲主要由以下四种方法实现迁移过程!
1:使用expdp/impdp数据泵导出导入,或者使用传统的exp/imp导入导出,后者效率低下;
2: 使用在线表空间迁移技术快速导出导入,前提是数据库的字符集要一致;
3:使用rman的备份进行异机恢复
4: 对单实例数据库构建基于rac的物理备库,进而切换备库为主库,这是生产环境中最为推荐的做法

本节中介绍使用expdp/impdp数据泵导出导入的方式实现迁移!

环境介绍:
数据库的版本均为10.2.0.5
操作系统的版本单实例数据库(源库)为rhel5.4 64 bit
rac(目标数据库)为ceontos4.8 64bit

一:查看源库的版本和表空间情况,同时在源库上建新的表空间和用户,插入数据,建立索引,创建目录对象,使用expdp到出用户的schema等

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

SQL> show parameter compat;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
compatible                           string      10.2.0.5.0
plsql_v2_compatibility               boolean     FALSE


SQL> select tablespace_name,file_name from dba_data_files;

 

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/orcl/users01.dbf
SYSAUX               /u01/app/oracle/oradata/orcl/sysaux01.dbf
UNDOTBS1             /u01/app/oracle/oradata/orcl/undotbs01.dbf
SYSTEM               /u01/app/oracle/oradata/orcl/system01.dbf
EXAMPLE              /u01/app/oracle/oradata/orcl/example01.dbf

SQL> create tablespace exp_rac datafile
  2  '/u01/app/oracle/oradata/orcl/exp_rac01.dbf' size 300M
  3  autoextend  on next 10M maxsize unlimited
  4* extent management local
Tablespace created.

SQL> create tablespace exp_rac_index datafile
  2  '/u01/app/oracle/oradata/orcl/exp_rac_index01.dbf' size 300M
  3  autoextend  on next 10M maxsize unlimited
  4* extent management local
Tablespace created.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/orcl/users01.dbf
SYSAUX               /u01/app/oracle/oradata/orcl/sysaux01.dbf
UNDOTBS1             /u01/app/oracle/oradata/orcl/undotbs01.dbf
SYSTEM               /u01/app/oracle/oradata/orcl/system01.dbf
EXAMPLE              /u01/app/oracle/oradata/orcl/example01.dbf
EXP_RAC              /u01/app/oracle/oradata/orcl/exp_rac01.dbf
EXP_RAC_INDEX        /u01/app/oracle/oradata/orcl/exp_rac_index01.dbf


SQL> create user test1 identified by oracle
  2  default tablespace exp_rac
  3  temporary tablespace temp
  4  quota unlimited on  exp_rac
  5* account unlock;
User created.

SQL> grant connect,resource to test1;
Grant succeeded.

SQL> create table test1.source as select * from dba_source;
Table created.

SQL> insert into test1.source select * from test1.source;
295491 rows created.

SQL> /
590982 rows created.

SQL> /
1181964 rows created.

SQL> commit;
Commit complete.

SQL> analyze table test1.source compute statistics;
Table analyzed.

SQL> select count(*) from test1.source;

  COUNT(*)
----------
   2363928

SQL> select sum(bytes/(1024*1024)) MB from dba_extents
  2  where segment_name='SOURCE'
  3  and owner='TEST1';

        MB
----------
       408

[oracle@server49 orcl]$ ll -h exp_rac01.dbf 
-rw-r----- 1 oracle oinstall 411M Jan  1 19:06 exp_rac01.dbf

SQL> create index test1.i_source 
  2  on test1.source(type) 
  3  tablespace exp_rac_index;
Index created.

SQL> select table_name,tablespace_name from dba_indexes
  2  where owner='TEST1' and index_name='I_SOURCE';

TABLE_NAME                     TABLESPACE_NAME
------------------------------ --------------------
SOURCE                         EXP_RAC_INDEX

SQL> create directory expdp_dir as '/home/oracle/expdp_dir';
Directory created.

SQL> grant read,write on directory expdp_dir to test1;
Grant succeeded.

SQL> !mkdir -p /home/oracle/expdp_dir

[oracle@server49 ~]$ expdp test1/oracle directory=expdp_dir dumpfile=source.dmp logfile=source.log  schemas=test1

Export: Release 10.2.0.5.0 - 64bit Production on Sunday, 01 January, 2012 19:38:30
Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "TEST1"."SYS_EXPORT_SCHEMA_01":  test1/******** directory=expdp_dir dumpfile=source.dmp 
logfile=source.log schemas=test1 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 408 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST1"."SOURCE"                            280.8 MB 2363928 rows
Master table "TEST1"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST1.SYS_EXPORT_SCHEMA_01 is:
  /home/oracle/expdp_dir/source.dmp
Job "TEST1"."SYS_EXPORT_SCHEMA_01" successfully completed at 19:39:03

 

二:复制expdp导出的相关文件到目标库上,同时在目标库上创建相应的用户和表空间以及目录对象等

[oracle@rac1 ~]$ sqlplus sys/123456@racdb as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sun Jan 1 20:28:52 2012
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select file_name,tablespace_name from dba_data_files;

FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- --------------------
+DATA/racdb/datafile/users.259.769960507           USERS
+DATA/racdb/datafile/sysaux.257.770222575          SYSAUX
+DATA/racdb/datafile/undotbs1.258.769205541        UNDOTBS1
+DATA/racdb/datafile/system.256.770588849          SYSTEM
+DATA/racdb/datafile/example.264.769205649         EXAMPLE
+DATA/racdb/datafile/undotbs2.265.769205765        UNDOTBS2
+DATA/racdb/datafile/local_arch_test.312.770588847 LOCAL_ARCH_TEST

SQL> create user test1 identified by oracle
  2  default tablespace users
  3  temporary tablespace temp
  4  account unlock;
User created.

SQL> grant connect,resource to test1;
Grant succeeded.

SQL> create directory expdp_dir as '/home/oracle/expdp_dir';
Directory created.

SQL> grant read,write on directory expdp_dir to test1;
Grant succeeded.

SQL> create tablespace exp_rac datafile size 500M;
Tablespace created.

SQL> create tablespace exp_rac_index datafile size 500M;
Tablespace created.

三:在目标数据库上使用impdp导入数据

[oracle@rac1 ~]$ impdp test1/oracle directory=expdp_dir dumpfile=source.dmp logfile=source.log schemas=test1
Import: Release 10.2.0.5.0 - 64bit Production on Sunday, 01 January, 2012 21:00:26
Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Master table "TEST1"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "TEST1"."SYS_IMPORT_SCHEMA_01":  test1/******** directory=expdp_dir dumpfile=source.dmp

logfile=source.log schemas=test1 
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST1"."SOURCE"                            280.8 MB 2363928 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "TEST1"."SYS_IMPORT_SCHEMA_01" successfully completed at 21:07:02

四:测试结果

[oracle@rac1 ~]$ sqlplus sys/123456@racdb as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Sun Jan 1 21:08:18 2012
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select count(*) from test1.source;

  COUNT(*)
----------
   2363928

SQL> col table_name format a20
SQL> col tablespace_name format a20
SQL> select table_name,tablespace_name from dba_indexes
  2  where owner='TEST1' and index_name='I_SOURCE';

TABLE_NAME           TABLESPACE_NAME
-------------------- --------------------
SOURCE               EXP_RAC_INDEX


SQL> select sum(bytes/(1024*1024)) MB from dba_extents
  2  where segment_name='I_SOURCE'
  3* and owner='TEST1'

      MB
----------

        56

本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/757510如需转载请自行联系原作者


ylw6006

相关实践学习
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
相关文章
|
3月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
4月前
|
存储 运维 关系型数据库
从MySQL到云数据库,数据库迁移真的有必要吗?
本文探讨了企业在业务增长背景下,是否应从 MySQL 迁移至云数据库的决策问题。分析了 MySQL 的优势与瓶颈,对比了云数据库在存储计算分离、自动化运维、多负载支持等方面的优势,并提出判断迁移必要性的五个关键问题及实施路径,帮助企业理性决策并落地迁移方案。
|
6月前
|
人工智能 运维 关系型数据库
数据库运维:mysql 数据库迁移方法-mysqldump
本文介绍了MySQL数据库迁移的方法与技巧,重点探讨了数据量大小对迁移方式的影响。对于10GB以下的小型数据库,推荐使用mysqldump进行逻辑导出和source导入;10GB以上可考虑mydumper与myloader工具;100GB以上则建议物理迁移。文中还提供了统计数据库及表空间大小的SQL语句,并讲解了如何使用mysqldump导出存储过程、函数和数据结构。通过结合实际应用场景选择合适的工具与方法,可实现高效的数据迁移。
1105 1
|
5月前
|
数据可视化 BI API
无缝对接云数据库:自定义报表生成工具在混合云环境下的部署指南
自定义报表生成工具通过拖拽设计、多数据源整合及自动化输出,帮助业务人员零代码创建个性化报表,解决传统工具灵活性不足、技术门槛高的问题。文章对比其与传统报表差异,列举行业应用场景(如财务、零售),并给出选型建议与主流工具(如FineReport、Power BI、板栗看板)的优劣势分析。
236 0
|
8月前
|
存储 关系型数据库 数据挖掘
【瑶池数据库动手活动及话题本周精选(体验ADB、 SelectDB,参与 RDS 迁移训练营)】(4.21-4.27)
本文为 “瑶池数据库动手活动及话题精选” 系列第一期,聚焦 SelectDB 日志分析、AnalyticDB Zero-ETL 集成、RDS 迁移训练营三大实战,设积分、实物等多重奖励,同步开启话题互动。点击链接参与,每周解锁数据库实战新场景。
|
8月前
|
SQL Oracle 关系型数据库
用 YashanDB Migration Platform,数据库迁移不再是“高风险动作”
数据库迁移一直是企业信息化中的难题,耗时长、风险高。YashanDB Migration Platform(YMP)提供一站式解决方案,涵盖评估、改写、迁移与校验全流程。其核心能力包括SQL自动适配、智能对象迁移、高性能数据通道及数据对比校验,显著降低人力成本与业务风险。适合从Oracle、MySQL等迁移到YashanDB的企业,以及需异构整合或国产化替代的集团、政府和国企项目。YMP不仅是工具,更是推动数据库国产化的关键平台。
|
6月前
|
关系型数据库 MySQL 数据库
MySQL数据库上云迁移
本文介绍了将数据库迁移到RDS for Mysql的两种主要方法:停服迁移和不停服迁移。停服迁移适合可短暂中断服务的场景,通过mysqldump或DTS完成;不停服迁移适用于需保持业务连续性的场景,推荐使用DTS实现结构、全量及增量数据迁移。文中详细列出了每种方法的具体操作步骤,帮助企业根据需求选择合适的迁移方案。
230 1
MySQL数据库上云迁移