Oracle单实例数据库迁移到Oracle RAC环境之--数据导出导入 系统环境: 操作系统:RedHat EL55 Oracle : Oracle 11.2.0.1.0 集群软件:Oracle GI 11.2.0.1.0 本案例采用的是通过数据的导入导出(EXPDP/IMPDP)的迁移方式 650) this.width=650;" src="http://w
Oracle单实例数据库迁移到Oracle RAC环境之--数据导出导入
系统环境:
操作系统:RedHat EL55
Oracle : Oracle 11.2.0.1.0
集群软件:Oracle GI 11.2.0.1.0
本案例采用的是通过数据的导入导出(EXPDP/IMPDP)的迁移方式
从单实例的库迁移数据到RAC环境,可以有多种方式,通过数据的导出和导入也可以,但前提是数据库采用相同的字符集。
1、数据库环境
单实例:
17:35:59 SYS@ test1>SELECT * FROM V$VERSION;
BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production Elapsed: 00:00:00.02
17:35:36 SYS@ test1>select userenv('LANGUAGE') FROM DUAL;
USERENV('LANGUAGE') ---------------------------------------------------- AMERICAN_AMERICA.ZHS16GBK
RAC 环境:
17:46:03 SYS@ prod1>SELECT * FROM V$VERSION;
BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production Elapsed: 00:00:00.16
17:46:29 SYS@ prod1>select instance_name,status from gv$instance;
INSTANCE_NAME STATUS ---------------- ------------ prod1 OPEN prod2 OPEN
17:45:40 SYS@ prod1>select userenv('LANGUAGE') FROM DUAL;
USERENV('LANGUAGE') ---------------------------------------------------- AMERICAN_AMERICA.ZHS16GBK
2、建立测试环境
单实例:
17:38:26 SYS@ test1>create tablespace test01
17:41:40 2 datafile '/dsk1/oradata/test1/test01.dbf' size 100m;
Tablespace created.
17:43:49 SYS@ test1>create user test1 identified by test1
17:44:00 2 default tablespace test01
17:44:00 3 temporary tablespace tmpgp1
17:44:00 4 quota unlimited on test01
17:44:00 5 account unlock;
17:44:00 SYS@ test1>grant connect ,resource to test1;
Grant succeeded.
17:50:34 SYS@ test1>conn test1/test1
Connected.
17:50:41 TEST1@ test1>create table testtb1 tablespace test01 as select * from scott.emp;
Table created.
Elapsed: 00:00:00.25
17:50:52 TEST1@ test1>create index test_empno_ind on testtb1(empno) tablespace indx;
Index created.
Elapsed: 00:00:00.05
如果做表空间传输,需要对表空间做自包含检测:
17:51:15 SYS@ test1>EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('test01', TRUE);
PL/SQL procedure successfully completed.
Elapsed: 00:01:04.07
17:52:25 SYS@ test1>SELECT * FROM TRANSPORT_SET_VIOLATIONS;
no rows selected
Elapsed: 00:00:00.05
创建导出传输目录:
17:52:43 SYS@ test1>create directory exp_dir as '/home/oracle/exp';
Directory created.
Elapsed: 00:00:00.07
17:53:24 SYS@ test1>grant read,write on directory exp_dir to test1;
Grant succeeded.
Elapsed: 00:00:00.06
17:53:39 SYS@ test1>!mkdir ~/exp
导出schema:
[oracle@rh6 exp]$ expdp test1/test1 directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1
Export: Release 11.2.0.1.0 - Production on Thu Jul 10 17:59:05 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Starting "TEST1"."SYS_EXPORT_SCHEMA_02": test1/******** directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1 Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 256 KB 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 . . exported "TEST1"."SYS_EXPORT_SCHEMA_01" 139.4 KB 1073 rows . . exported "TEST1"."TESTTB1" 8.570 KB 14 rows Master table "TEST1"."SYS_EXPORT_SCHEMA_02" successfully loaded/unloaded ****************************************************************************** Dump file set for TEST1.SYS_EXPORT_SCHEMA_02 is: /home/oracle/exp/test.dmp Job "TEST1"."SYS_EXPORT_SCHEMA_02" successfully completed at 17:59:28
3、在RAC环境下导入数据:
从单实例传输dump文件到RAC环境下:
[oracle@rh6 exp]$ scp *.dmp 192.168.8.21:/u01/exp
The authenticity of host '192.168.8.21 (192.168.8.21)' can't be established. RSA key fingerprint is 39:04:88:3b:54:34:3c:34:d2:df:74:37:fe:5f:92:2d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.8.21' (RSA) to the list of known hosts. oracle@192.168.8.21's password: test.dmp 100% 428KB 428.0KB/s 00:00
在RAC下建立表空间和Schema:
18:16:28 SYS@ prod1>create tablespace test01; Tablespace created. Elapsed: 00:00:06.27 18:19:19 SYS@ prod1>create tablespace indx; Tablespace created. Elapsed: 00:00:05.81 18:19:36 SYS@ prod1>select file_name,file_id,tablespace_name,bytes/1024/1024 from dba_data_files; FILE_NAME FILE_ID TABLESPACE_NAME BYTES/1024/1024 -------------------------------------------------- ---------- --------------------------- +DG1/prod/datafile/users.259.852387481 4 USERS 5 +DG1/prod/datafile/undotbs1.258.852292707 3 UNDOTBS1 105 +DG1/prod/datafile/sysaux.257.852292707 2 SYSAUX 630 +DG1/prod/datafile/system.256.852292703 1 SYSTEM 690 +DG1/prod/datafile/example.264.852292891 5 EXAMPLE 103.125 +DG1/prod/datafile/undotbs2.265.852293259 6 UNDOTBS2 50 +DG1/prod/datafile/tbs1.269.852376681 7 TBS1 100 +DG1/prod/datafile/test01.273.852574753 8 TEST01 100 +DG1/prod/datafile/indx.274.852574771 9 INDX 100 9 rows selected.
18:14:34 SYS@ prod1>create user test1 identified by test1 18:14:49 2 default tablespace users 18:14:49 3 temporary tablespace temp 18:14:49 4 quota unlimited on users 18:14:49 5 account unlock; User created. Elapsed: 00:00:00.15 18:14:50 SYS@ prod1> 18:14:50 SYS@ prod1>grant connect,resource to test1; Grant succeeded.
建立数据导入目录:
18:15:31 SYS@ prod1>create directory imp_dir as '/u01/exp'; Directory created. 18:16:08 SYS@ prod1>grant read,write on directory imp_dir to test1; Grant succeeded. Elapsed: 00:00:00.16 [root@node1 ~]# mkdir -p /u01/exp [root@node1 ~]# chown -R oracle:dba /u01/exp
导入数据:
[root@node1 ~]# su - oracle
[oracle@node1 ~]$ cd /u01/exp
[oracle@node1 exp]$ ls
test.dmp
[oracle@node1 exp]$ impdp test1/test1 directory=imp_dir dumpfile=test.dmp logfile=test.log schemas=test1
Import: Release 11.2.0.1.0 - Production on Thu Jul 10 18:21:05 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, Real Application Clusters, Automatic Storage Management, 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=imp_dir dumpfile=test.dmp logfile=test.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"."SYS_EXPORT_SCHEMA_01" 139.4 KB 1073 rows . . imported "TEST1"."TESTTB1" 8.570 KB 14 rows 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 Job "TEST1"."SYS_IMPORT_SCHEMA_01" successfully completed at 18:21:42
数据导入成功!
4、验证:
18:19:45 SYS@ prod1>conn test1/test1 Connected. 18:22:20 TEST1@ prod1>select * from tab; TNAME TABTYPE CLUSTERID ------------------------------ ------- ---------- SYS_EXPORT_SCHEMA_01 TABLE TESTTB1 TABLE Elapsed: 00:00:00.08 18:22:24 TEST1@ prod1>select * from testtb1; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 40 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. Elapsed: 00:00:00.02 18:22:34 TEST1@ prod1> 17:47:08 SYS@ prod2>conn test1/test1 Connected. 18:22:54 TEST1@ prod2>select * from testtb1; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 40 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. Elapsed: 00:00:00.31
数据导入错误案例:
错误(1):
[oracle@rh6 ~]$ expdp test1/test1 directory=exp_dir dumpfile=~/exp/test.dmp logfile=~/exp/test.log schemas=test1
Export: Release 11.2.0.1.0 - Production on Thu Jul 10 17:55:21 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39088: file name cannot contain a path specification
在dumpfile和logfile指定的参数不能指定路径!
错误(2):
[oracle@rh6 ~]$ cd exp
[oracle@rh6 exp]$ expdp test1/test1 directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1
Export: Release 11.2.0.1.0 - Production on Thu Jul 10 17:56:19 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "TEST1"."SYS_EXPORT_SCHEMA_01": test1/******** directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
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
UDE-04031: operation generated ORACLE error 4031
ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","SELECT job_id FROM v$datapum...","SQLA","tmp")
ORA-06512: at "SYS.KUPV$FT_INT", line 2904
ORA-06512: at "SYS.KUPC$QUE_INT", line 572
ORA-25254: time-out in LISTEN while waiting for a message
ORA-06512: at "SYS.DBMS_DATAPUMP", line 3263
ORA-06512: at "SYS.DBMS_DATAPUMP", line 4488
ORA-06512: at line 1
出现了ORA-04031错误,应该和share pool 有关系!
查看系统共享池:
17:57:59 SYS@ test1>show parameter shared
NAME TYPE VALUE ------------------------------------ -------------------------------- ------------------- hi_shared_memory_address integer 0 max_shared_servers integer shared_memory_address integer 0 shared_pool_reserved_size big integer 12M shared_pool_size big integer 112M shared_server_sessions integer shared_servers integer 0
调整share pool的size:
17:58:01 SYS@ test1>alter system set shared_pool_size=200m ;
System altered.
Elapsed: 00:00:00.65
调整后重新导出成功:
[oracle@rh6 exp]$ expdp test1/test1 directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1
Export: Release 11.2.0.1.0 - Production on Thu Jul 10 17:59:05 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Starting "TEST1"."SYS_EXPORT_SCHEMA_02": test1/******** directory=exp_dir dumpfile=test.dmp logfile=test.log schemas=test1 Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 256 KB 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 . . exported "TEST1"."SYS_EXPORT_SCHEMA_01" 139.4 KB 1073 rows . . exported "TEST1"."TESTTB1" 8.570 KB 14 rows Master table "TEST1"."SYS_EXPORT_SCHEMA_02" successfully loaded/unloaded ****************************************************************************** Dump file set for TEST1.SYS_EXPORT_SCHEMA_02 is: /home/oracle/exp/test.dmp Job "TEST1"."SYS_EXPORT_SCHEMA_02" successfully completed at 17:59:28
@至此,数据迁移完成!

MySQL是一种开源的关系型数据库管理系统,主要用于快速、可靠地存储和检索数据。其工作原理包括客户端请求、查询解析、执行查询和返回结果。使用示例包括创建表、插入和查询数据,以及高级功能如JOIN操作。常见错误涉及SQL语法、数据类型和权限问题,优化建议包括使用索引、优化查询和分表分区。

MySQL是一个开源的关系型数据库管理系统,适用于数据存储、管理、查询和安全。1.它支持多种操作系统,广泛应用于Web应用等领域。2.通过客户端-服务器架构和不同存储引擎,MySQL高效处理数据。3.基本用法包括创建数据库和表,插入、查询和更新数据。4.高级用法涉及复杂查询和存储过程。5.常见错误可通过EXPLAIN语句调试。6.性能优化包括合理使用索引和优化查询语句。

选择MySQL的原因是其性能、可靠性、易用性和社区支持。1.MySQL提供高效的数据存储和检索功能,支持多种数据类型和高级查询操作。2.采用客户端-服务器架构和多种存储引擎,支持事务和查询优化。3.易于使用,支持多种操作系统和编程语言。4.拥有强大的社区支持,提供丰富的资源和解决方案。

InnoDB的锁机制包括共享锁、排他锁、意向锁、记录锁、间隙锁和下一个键锁。1.共享锁允许事务读取数据而不阻止其他事务读取。2.排他锁阻止其他事务读取和修改数据。3.意向锁优化锁效率。4.记录锁锁定索引记录。5.间隙锁锁定索引记录间隙。6.下一个键锁是记录锁和间隙锁的组合,确保数据一致性。

MySQL查询性能不佳的原因主要包括没有使用索引、查询优化器选择错误的执行计划、表设计不合理、数据量过大和锁竞争。 1.没有索引导致查询缓慢,添加索引后可显着提升性能。 2.使用EXPLAIN命令可以分析查询计划,找出优化器错误。 3.重构表结构和优化JOIN条件可改善表设计问题。 4.数据量大时,采用分区和分表策略。 5.高并发环境下,优化事务和锁策略可减少锁竞争。

在数据库优化中,应根据查询需求选择索引策略:1.当查询涉及多个列且条件顺序固定时,使用复合索引;2.当查询涉及多个列但条件顺序不固定时,使用多个单列索引。复合索引适用于优化多列查询,单列索引则适合单列查询。

要优化MySQL慢查询,需使用slowquerylog和performance_schema:1.启用slowquerylog并设置阈值,记录慢查询;2.利用performance_schema分析查询执行细节,找出性能瓶颈并优化。

MySQL和SQL是开发者必备技能。1.MySQL是开源的关系型数据库管理系统,SQL是用于管理和操作数据库的标准语言。2.MySQL通过高效的数据存储和检索功能支持多种存储引擎,SQL通过简单语句完成复杂数据操作。3.使用示例包括基本查询和高级查询,如按条件过滤和排序。4.常见错误包括语法错误和性能问题,可通过检查SQL语句和使用EXPLAIN命令优化。5.性能优化技巧包括使用索引、避免全表扫描、优化JOIN操作和提升代码可读性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

记事本++7.3.1
好用且免费的代码编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。