oracle10g 数据库跨平台迁移(表空间传输)
1 项目概述 由于客户现有的这套windows2003平台上的oracle10g数据库在性能和可维护性上不能满足需要,客户决定将数据库从windows平台迁移到Linux平台。综合停机时间等方面因素后决定使用表空间传输的方法来实施本次数据库迁移。 · aspectratio=t v:ext=edit
1 项目概述
由于客户现有的这套windows2003平台上的oracle10g数据库在性能和可维护性上不能满足需要,客户决定将数据库从windows平台迁移到Linux平台。综合停机时间等方面因素后决定使用表空间传输的方法来实施本次数据库迁移。
· aspectratio="t" v:ext="edit">
a.本文的背景是Linux平台上的数据库已经安装完成,安装过程并不在本文的讨论范围。 b.本次是在模拟的实验环境下进行的,实际始终需要停止掉listener. |
2 表空间传输概述
2.1 关于表空间
可传输表空间的特性主要用于进行库对库的表空间复制,要进行传输的表空间必须置于 read-only模式。如果生产库不允许表空间置为只读模式,没关系,方法还是有的,通过 RMAN 备份也可以创建可传输表空间集。要使用 可传输表空间的 特性,oracle 至少是 8i 企业版或更高版本。如果是相同操作系统平台相互导入,则8i及以上 版本均可支持,但如果是不同操作系统平台,数据库版本至少 10g 。被传输的表空间即可以是字典管理,也可以是本地管理。并且自 oracle9i 开始,被传输表空间的 block size 可以与目标数据库的 block size 不同.可传输表空间(还有个集)最大的优势是其速度比 export/import 或 unload/load 要快的多。因为可传输表空间主要是复制数据文件到目标路径,然后再使用 export/import或 Data Pump export/import 等应用仅导出/导入表空间对象的元数据到新数据库。
通常有两种方式传输表空间:
1) 手工操作。
按本节中的步骤操作,含 SQL*Plus, RMAN, IMP/EXP 或 Data Pump 等各种指令操作。
2) 使用 OEM 中的传送表空间向导。
要运行传送表空间向导:
? 使用具有 EXP_FULL_DATABASE 角色的用户登陆到 OEM 中 ;
? 点击维护 (Maintenance) 链接 ;
? 点击标题下方的 "Transport Tablespaces" 。
2.2 跨平台表空间传输
从oracle10g开始,可以实现跨平台传输表空间。有很多平台可以支持跨平台的传送.可以通过查询V$TRANSPORTABLE_PLATFORM视图来确认哪些平台可以支持,该视图同时也可以获取各平台的ENDIAN_FORMAT( 字节顺序 byte ordering)
SQL>SELECT*FROMV$TRANSPORTABLE_PLATFORM ORDER BY PLATFORM_ID;
PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ---------------------------------------- --------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
3 HP-UX (64-bit) Big
4 HP-UX IA (64-bit) Big
5 HP Tru64 UNIX Little
6 AIX-Based Systems (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
10 Linux IA (32-bit) Little
11 Linux IA (64-bit) Little
12 Microsoft Windows 64-bit for AMD Little
13 Linux 64-bit for AMD Little
15 HP Open VMS Little
16 Apple Mac OS Big
17 Solaris Operating System (x86) Little
18 IBM Power Based Linux Big
提示:关于字节顺序 (byte ordering)
一些操作系统(包括 Windows )在低位内存地址中用最低有效字节存储多字节二进制数据;因此这种系统被称为低地址低字节序。相反,其它的操作系统(包括 Solaris )将最高有效字节存储在低位内存地址中,因此这种系统被称为低地址高字节序。当一个低地址高字节序的系统试图从一个低地址低字节序的系统中读取数据时,需要一个转换过程 — 否则,字节顺序将导致不能正确解释读取的数据。不过,当在相同字节顺序的平台之间传输表空间时,不需要任何转换。
如果平台间的 endian不同,那么在执行导入操作之之前必须首先转换源平台的表空间到目标格式, 如果平台间 endian format 相同,则可以跳过转换的步骤,即使是不同平台。当然前提是各平台的数据库版本都不低于10g。
3 数据库迁移实施
3.1 确定平台字节顺序
在确定使用表空间传输技术实施数据库钱以后,我们首先要做的就是确定现有数据库平台和目标平台的字节顺序,从而决定是否需要进行数据转换。具体操作如下:
以下操作在源主机(windows):
C:\Users\lenovo>sqlplus sys/Wxpt-2010@testdb as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on 星期二 12月 7 10:34:56 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>SELECT d.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;
PLATFORM_NAME
--------------------------------------------------------------------------------
ENDIAN_FORMAT
--------------
Microsoft Windows x86 64-bit
Little
以下操作在目标主机:
SQL> SELECT d.PLATFORM_NAME, ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;
PLATFORM_NAME
--------------------------------------------------------------------------------
ENDIAN_FORMAT
--------------
Linux IA (32-bit)
Little
3.2 查看用户及表空间信息
我们可以通过sql语句查询源数据库上的表空间及用户信息,确定要传输
的表空间。本次实验客户要传输的表空为:SY812T,PRODCTLT,CRPDTAT,DV812T,SVM812T,OL812T等
3.3 确定表空关联性
在我们确定了需要迁移的表空间后,还需要对表空间的关联性进行确认,如果表空间不是自包含的,则需要将与其关联的表空间一同进行传输。
以下操作均在源主机操作:
SQL> execute dbms_tts.transport_set_check('SY812T',TRUE);
SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS;
Index SY812.F98511_0 in tablespace SY812I enforces primary constriants of table SY812.F98511 in tablespace SY812T
Index SY812.F98513_0 in tablespace SY812I enforces primary constriants of table SY812.F98513 in tablespace SY812T
Index SY812.F986101_0 in tablespace SY812I enforces primary constriants of table SY812.F986101 in tablespace SY812T
Index SY812.F98611_0 in tablespace SY812I enforces primary constriants of table
VIOLATIONS
--------------------------------------------------------------------------------
SY812.F98611 in tablespace SY812T
Index SY812.F986110_0 in tablespace SY812I enforces primary constriants of table SY812.F986110 in tablespace SY812T
Index SY812.F986111_0 in tablespace SY812I enforces primary constriants of tabe SY812.F986111 in tablespace SY812T
Index SY812.F986113_0 in tablespace SY812I enforces primary constriants of table SY812.F986113 in tablespace SY812T
·
a.只要结果非空表空间就是非自包含的。 b.上述结果只截取了部分输出. |
根据以上输出,可以看出SY812T表空间是非自包含的,SY812T有一个SY812I的索引表空间,我们在做表空间传输时需要连同SY812I一起传输。
创建一个exdp的通道来存放更改结构后的文件:
SQL> create directory tran as 'E:\tran';
传输前,我们需要修改要传输的表空间为只读:
SQL> alter tablespace SY812T read only;
表空间已更改。
SQL> alter tablespace SY812I read only;
表空间已更改。
3.4 导出表结构
以下操作在源主机上:
C:\Documents and Settings\jdenew>expdp system/Wxpt-2010 directory=tran transport
_tablespaces=SY812T,SY812I
Export: Release 10.2.0.4.0 - 64bit Production on Tuesday, 07 December, 2010 10:53:18
Copyright (c) 2003, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01": system/******** directory=tran
transport_tablespaces=SY812T,SY812I
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX/STATISTICS/FUNCTIONAL_AND_BITM
AP/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/TABLE_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
E:\TRAN\EXPDAT.DMP
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 10:53:50
3.5 转换平台
如果两个平台的字节顺序相同如:都为little或者都为big,则不需要进行平台转换,可直接跳到3.6步骤,本文档由于两个平台是相同的字节顺序字节转换不需要进行,此处的描述目的是说明字节顺序不同的平台间该如何处理。
以下操作在源主机上:
C:\Documents and Settings\jdenew>rman target sys/Wxpt-2010@testdb nocatalog
Recovery Manager: Release 10.2.0.4.0 - Production on Tue Dec 7 13:49:34 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: TESTDB (DBID=2499148843)
using target database control file instead of recovery catalog
RMAN> convert tablespace SY812T,SY812I to platform 'Linux IA (32-bit)' db_file_n
ame_convert 'E:\ORATBL\ORCL\','E:\tran\' 'F:\ORAIND\ORCL\','E:\tran\';
·
1. 其中E:\ORATBL\ORCL\和F:\ORAIND\ORCL\'分别是SY812T,SY812I这两个表空间存放位置,我们可以通过toad或者只用sql语句进行查询。 2. 'Linux IA (32-bit)为3.1节中select语句的输出,分毫不可差。 |
Starting backup at 07-DEC-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00006 name=F:\ORAIND\ORCL\SY812I01.DBF
converted datafile=E:\TRAN\SY812I01.DBF
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00005 name=E:\ORATBL\ORCL\SY812T01.DBF
converted datafile=E:\TRAN\SY812T01.DBF
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:07
Finished backup at 07-DEC-10
3.6 传输数据
数据转换完成后,从源主机用ftp 方式把在/E/tran目录下生成的文件以二进制的方式传输到目标机器lunix上的/oradata/train路径下。
·
1./E/tran和/oradata/train可以根据实际情况进行创建,并修改权限为oracle/dba |
3.7 创建用户及导入数据
数据传输完成后,我们要在目标主机上按照源主机上用户情况进行用户的创建。
以下操作在目标主机上:
[oracle@lenovo01130593 tran]$create user PRODCTL identified by oracle;
[oracle@lenovo01130593 tran]$grant connect,resource to PRODCTL;
用户创建完成后,我们导入3.6步传输过来的数据:
[oracle@lenovo01130593 tran]$ impdp system/oracle dumpfile=EXPDAT.DMP directory=tran exclude=transportable_export/table_statistics,transportable_export/grant/owner_grant/object_grant transport_datafiles=/oradata/tran/PRODCTLT01.DBF,/oradata/tran/PRODCTLI01.DBF
Import: Release 10.2.0.4.0 - Production on Tuesday, 07 December, 2010 14:13:56
Copyright (c) 2003, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting"SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":system/******** dumpfile=EXPDAT.DMPdirectory=tran exclude=transportable_export/table_statistics,transportable_export/grant/owner_grant/object_grant transport_datafiles=/oradata/tran/PRODCTLT01.DBF,/oradata/tran/PRODCTLI01.DBF
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/CONSTRAINT/CONSTRAINT
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 14:14:17
3.8 一致性确认
数据导入完成后,我们要对导入后的数据进行验证,验证的方法就是比对导入前后的内容即可。
以下在目标主机上操作:
SQL> connect /as sysdba
Connected.
SQL> select count(*) from dba_tables where owner='PRODCTL';
COUNT(*)
--------------------------------
67

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.