从linux到windows传输数据库
准备工作 一、实验目的 从linux 系统到windows 系统,传输整个数据库
二、准备工作 | | | | | | | | | | | | | | Microsoft Windows x86 64-bit |
三、限制要求
要从一个平台向另一个平台移动数据库,必须确保源系统和目标系统都运行于v$transportable_platform中列出的平台上,并且具有相同的endian格式。此功能与可移动表空间不同,可移动表空间有一个可以插入数据的目标数据库,而此功能将在目标平台上创建新的数据库。新创建的数据库种包含的数据与源数据库中相同,除了数据库名、实例名和文件位置等,新数据库与源数据库的设置也相同。 (这里我之前一直有个误解,endian format不是说,64位与32位字节格式不一样,而是指v$transportable_platform中endian_format列的big和little不一样)
四、实验规划
必须先以只读模式打开数据库,然后才能移动该数据库。然后使用RMAN转换数据库的必要数据文件。 在源平台执行转换时,RMAN命令CONVERT DATABASE将生成一个包含正确的CREATE CONTROLFILE RESETLOGS命令的脚本,此命令用于在目标系统上创建新数据库。然后CONVERT DATABASE 命令将装换识别出的所有数据文件,以便这些文件可以在目标系统上使用。接着,需要将已转换的数据文件和生成的脚本传送到目标平台。通过目标平台上执行生成的脚本,创建数据库的新副本。 注:源数据库必须在COMPATIBLE初始化参数设为10.0.0或者更高的条件下运行。自COMPATIBLE设置10.0.0或更高版本以来,识别出的所有表空间必须至少已被读写过一次。(教材原内容) 实验开始
一、查看endian(源库、目标库)
1.查看可传输数据库的平台
SQL> select * from v$transportable_platform; PLATFORM_IDPLATFORM_NAME ENDIAN_FORMAT --------------------------------------------------- -------------- 1 Solaris[tm] OE (32-bit) Big 2 Solaris[tm] OE (64-bit) Big 7 Microsoft Windows IA (32-bit) Little 10 Linux IA (32-bit) Little 6 AIX-Based Systems (64-bit) Big 3 HP-UX (64-bit) Big 5 HP Tru64 UNIX Little 4 HP-UX IA (64-bit) Big 11 Linux IA (64-bit) Little 15 HP Open VMS Little 8 Microsoft Windows IA (64-bit) Little
PLATFORM_IDPLATFORM_NAME ENDIAN_FORMAT --------------------------------------------------- -------------- 9 IBM zSeries Based Linux Big 13 Linux x86 64-bit Little 16 Apple Mac OS Big 12 Microsoft Windows x86 64-bit Little 17 Solaris Operating System (x86) Little 18 IBM Power Based Linux Big 19 HP IA Open VMS Little 20 Solaris Operating System(x86-64) Little 21 Apple Mac OS (x86-64) Little 20 rowsselected.
2.源数据库查看endian格式
SQL>select d.platform_name,tp.endian_format 2 fromv$transportable_platform tp,v$database d 3 where tp.platform_name=d.platform_name; PLATFORM_NAME ENDIAN_FORMAT ------------------------------------------------------ Linux IA(32-bit) Little 二、在源数据库转换
1.查看源数据库打开方式 SQL> select open_mode from v$database; OPEN_MODE -------------------- READ WRITE
2.修改源库为只读模式
SQL> startup mount; SQL> alter database open read only; Database altered. SQL> select open_mode from v$database; OPEN_MODE -------------------- READ ONLY
三、转换前的检验
利用DBMS_TDB包检验数据库能否被传输以及列出外部表和DIRECTORY等无法传输的信息。
1.对源数据库执行dbms_tdb.check_db检查
SQL> setserveroutput on (设置环境变量serveroutput为打开状态,使PL/SQL程序在SQL*plus中输出结果) SQL>declare db_ready boolean; (定义db_ready变量为布尔型) begin db_ready:=dbms_tdb.check_db('MicrosoftWindows x86 64-bit'); (给db_ready赋值,使用dbms_tdb包检查目标平台) end; / PL/SQLprocedure successfully completed. (如果没有输出内容,就可以了)
2.对源数据库执行dbms_tdb.check_external来识别外部对象
SQL> setserveroutput on SQL>declare external boolean; begin external:=dbms_tdb.check_external;(使用dbms_tdb检查外部对象) end; / ##如下也可以忽略 The following external tables exist in the database: SH.SALES_TRANSACTIONS_EXT The following directories exist in the database: SYS.DATA_FILE_DIR, SYS.MEDIA_DIR, SYS.LOG_FILE_DIR,SYS.SS_OE_XMLDIR, SYS.XMLDIR, SYS.SUBDIR, SYS.ORACLE_OCM_CONFIG_DIR2,SYS.ORACLE_OCM_CONFIG_DIR, SYS.DATA_PUMP_DIR The following BFILEs exist in the database: PM.PRINT_MEDIA
PL/SQLprocedure successfully completed.
四、备份源库
RMAN>backup as compressed backupsetdatabase plus archivelog delete all input;
五、利用RMAN把数据库转换成目标平台格式
1、查看数据库实例名
SQL> select name from v$database; NAME --------- SZTECH1
2.用 CONVERT DATABASE命令转换数据库
RMAN>convert database new database 'SZTECH1' 2> transport script '/u01/backup/transport.sql'to platform 'Microsoft Windows x86 64-bit' 3> db_file_name_convert '/u01/app/oracle/oradata/sztech1''/u01/backup'; Finished Control File and SPFILE Autobackup at24-MAR-18
##注意: 1)new database 表示目标数据库的名字, 2)transport script 指定生成建库脚本的位置 3)to platform 表示目标数据库的平台 4)db_file_name_convert 中 指定源数据库数据文件所在的位置/u01/app/oracle/oradata/sztech1 和转换后数据文件的存放位置/u01/backup
##中途生成报错:ORA-19502: write error on file"/u01/backup/sysaux01.dbf", block number 46336 (block size=8192) ORA-27072: File I/O error
查看alert.log日志,没有生成报错信息。 [报错原因] 提示是I/O发生错误,所以怀疑是不是备份路径的空间,发现是因为空间满了
3.查看/u01/backup路径下的文档
[oracle@dbserver backup]$ ls example01.dbf sysaux01.dbf transport.sql users01.dbf rcat_tbs01.dbf system01.dbf undotbs01.dbf
其中有1个脚本和转化后的数据文件
六、修改Linux参数文件
1.找到参数文件 通过查看生成的/u01/backup/transport.sql,查找出生成的参数文件是STARTUP NOMOUNTPFILE='/u01/app/oracle/product/11.2.0/db_1/dbs/init_00sui4dl_1_0.ora'
2.修改参数文件 vi/u01/app/oracle/product/11.2.0/db_1/dbs/init_00sui4dl_1_0.ora 将里面的内容修改成如下: # Please change the values of the followingparameters: control_files = "D:\oracle\product\11.2.0\db_1\dbs\control01.ctl" db_recovery_file_dest ="D:\oracle\fast_recovery_area" db_recovery_file_dest_size= 4353687552 audit_file_dest = "D:\oracle\product\11.2.0\db_1\dbs\adump" db_name = "SZTECH1" # Please review the values of the followingparameters: # __oracle_base = "D:\oracle" __shared_pool_size =75497472 __large_pool_size = 8388608 __java_pool_size = 4194304 __streams_pool_size = 0 __sga_target =197132288 __db_cache_size =100663296 __shared_io_pool_size = 0 remote_login_passwordfile= "EXCLUSIVE" db_domain ="" dispatchers ="(PROTOCOL=TCP) (SERVICE=sztech1XDB)" __pga_aggregate_target =171966464 # The values of the following parameters are fromsource database: processes = 150 memory_target =369098752 db_block_size = 8192 compatible = "11.2.0.4.0" undo_tablespace ="UNDOTBS1" audit_trail ="OS" open_cursors = 300 # diagnostic_dest = "D:\oracle" 修改完成后,把它复制到目标数据库的%oracle_home%/dbs/initsztech1.ora文件
七、修改生成的SQL脚本
STARTUP NOMOUNT PFILE='D:\oracle\product\11.2.0\db_1\dbs\initsztech1.ora' CREATE CONTROLFILE REUSE SET DATABASE"SZTECH1" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1'D:\oracle\oradata\sztech1\redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 'D:\oracle\oradata\sztech1\redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3'D:\oracle\oradata\sztech1\redo03.log' SIZE 50M BLOCKSIZE 512 DATAFILE 'D:\oracle\oradata\sztech1\system01.dbf', 'D:\oracle\oradata\sztech1\sysaux01.dbf', 'D:\oracle\oradata\sztech1\undotbs01.dbf', 'D:\oracle\oradata\sztech1\users01.dbf', 'D:\oracle\oradata\sztech1\example01.dbf' CHARACTER SET ZHS16GBK ; -- Database can now be opened zeroing the onlinelogs. ALTER DATABASE OPEN RESETLOGS UPGRADE; -- Commands to add tempfiles to temporarytablespaces. -- Online tempfiles have complete spaceinformation. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE 'D:\oracle\oradata\temp01.dbf' SIZE30408704 AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; -- End of tempfile additions. -- set echo off prompt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prompt * Your database has been createdsuccessfully! prompt * There are many things to think about forthe new database. Here prompt * is a checklist to help you stay on track: prompt * 1. You may want to redefine the locationof the directory objects. prompt * 2. You may want to change the internaldatabase identifier (DBID) prompt * or the global database name for this database. Use the prompt * NEWDBID Utility (nid). prompt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SHUTDOWN IMMEDIATE STARTUP UPGRADE PFILE='D:\oracle\product\11.2.0\db_1\dbs\initsztech1.ora' @@ ?/rdbms/admin/utlirp.sql SHUTDOWN IMMEDIATE STARTUP PFILE='D:\oracle\product\11.2.0\db_1\dbs\initsztech1.ora' -- The following step will recompile all PL/SQLmodules. -- It may take serveral hours to complete. @@ ?/rdbms/admin/utlrp.sql set feedback 6;
八、在目标数据库种还原数据库1、在目标数据库仅安装数据库软件,不建库2、在目标数据库上创建如下目录
C:\Users\administrator> md D:\oracle\oradata\sztech1 C:\Users\administrator > md D:\oracle\admin\sztech1\adump C:\Users\administrator > md D:\oracle\diag\rdbms\sztech1\trace C:\Users\administrator > md D:\oracle\fast_recovery_area\sztech1 C:\Users\administrator > md D:\oracle\diag\rdbms\sztech1\sztech1\cdump C:\Users\administrator > md D:\oracle\product\11.2.0\db_1\dbs
3、拷贝相关文件到如下位置
把RMAN转换时生成的数据文件、生成并修改过的SQL脚本和参数文件拷贝到如下位置
D:\oracle\oradata\sztech1\SYSTEM01.DBF D:\oracle\oradata\sztech1\UNDOTBS01.DBF D:\oracle\oradata\sztech1\SYSAUX01.DBF D:\oracle\oradata\sztech1\USERS01.DBF D:\oracle\oradata\sztech1\EXAMPLE01.DBF D:\oracle\product\11.2.0\db_1\dbs\initsztech1.ora D:\oracle\oradata\sztech1\transport.sql
4、windows上创建新的实例sztech1
C:\Users\administrator >oradim -new -sid sztech1 C:\Users\administrator > set oracle_sid=sztech1
5.利用新的pfile开启实例
C:\Users\administrator > sqlplus / as sysdba (已连接空闲实例) SQL> startup pfile='D\oracle\product\11.2.0\db_1\dbs\initsztech1.ora'; 这时会遇到ORA-00205问题,这是控制文件的问题,先不用管
6.查看当前实例状态
SQL> select status from v$instance; STATUS ------------ OPENED
7.执行脚本
SQL>@ D:\oracle\oradata\sztech1\transport.sql 此时,数据库移动已经完成。
九、传输后续工作
1.创建spfile SQL> startup nomount; SQL> create spfile from pfile='D:\oracle\product\11.2.0\db_1\dbs\initsztech1.ora'; SQL> alter database open; SQL> show parameter spfile;(查看spfile位置)
2.查看控制文件位置
SQL> select * from v$controlfile;
3.查看日志文件位置 SQL> select * from v$logfile; --------- end ------------
希望各位老师指点!
|