-环境、
源库:
IP:192.168.5.25
global_name:prod.net
目标库:
IP:192.168.5.27
global_name:db2.net
-源库
SQL> show parameter global_name;
如:values=false,则使用下语句更改成true
SQL> alter system set global_names=true scope=both;
SQL> show parameter compatible;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
compatible string 10.2.0.3.0
------------------------------------ ----------- ------------------------------
compatible string 10.2.0.3.0
SQL> show parameter aq;
如:values=0,则使用以下语句更改
SQL> alter system set aq_tm_processes=4 scope=both;
SQL> show parameter job;
手工添加额外的辅助日志:【如采用dbma_streams_adm配置streams时,辅助日志的增加过程是被隐式包含在配置脚本中】
SQL> alter database add supplemental log data(primary key,unique) columns;
每个需要配置streams的数据库,都需要创建一个streams的管理用户【最好设置单独的表空间】
SQL> create user stradmin identified by stradmin;
SQL> grant dba to stradmin;
创建一个连接到目标数据库的db link【注意:这里使用的是streams账户】
首先添加源库、目标库的tnsname.ora、linster.ora配置文件,具体请看另一文章:添加tnsname.ora、linster.ora
SQL> conn stradmin/stradmin;
SQL> create database link db2.net connect to stradmin identified by stradmin using 'db2';
SQL> create database link db2.net connect to stradmin identified by stradmin using 'db2';
SQL>declare
empty_tbs dbms_streams_tablespace_adm.tablespace_set;
begin
dbms_streams_adm.pre_instantiation_setup(
maintain_mode => 'GLOBAL',
tablespace_names => empty_tbs,
source_database => 'prod.net',
destination_database => 'db2.net',
perform_actions => true,
bi_directional => true,
include_ddl => true,
start_processes => true,
exclude_schemas => 'SYSMAN',
exclude_flags => dbms_streams_adm.exclude_flags_unsupported +
dbms_streams_adm.exclude_flags_dml +
dbms_streams_adm.exclude_flags_ddl);
end;
empty_tbs dbms_streams_tablespace_adm.tablespace_set;
begin
dbms_streams_adm.pre_instantiation_setup(
maintain_mode => 'GLOBAL',
tablespace_names => empty_tbs,
source_database => 'prod.net',
destination_database => 'db2.net',
perform_actions => true,
bi_directional => true,
include_ddl => true,
start_processes => true,
exclude_schemas => 'SYSMAN',
exclude_flags => dbms_streams_adm.exclude_flags_unsupported +
dbms_streams_adm.exclude_flags_dml +
dbms_streams_adm.exclude_flags_ddl);
end;
使用 RMAN复制源库到目标库
RMAN> backup database plus archivelog delete input;
马上取得SCN号,当还原并恢复到目标数据库的时候,需要指定只恢复到当前的SCN即可。
SQL> set serveroutput on size 1000000;
SQL>declare
until_scn number;
begin
until_scn:= dbms_flashback.get_system_change_number;
dbms_output.put_line('until SCN:' || until_scn);
end;
until_scn number;
begin
until_scn:= dbms_flashback.get_system_change_number;
dbms_output.put_line('until SCN:' || until_scn);
end;
如:until SCN:504351
归档当前在线日志
SQL> alter system archive log current;
创建pfile【目标库启动到Nomount的时候要用到】
SQL> create pfile from spfile;
分别复制备份文件、pfile到目标库对应位置
cd /u01/app/flash_recovery_area/
scp -r PROD
[email protected]:/u01/app/flash_recovery_area/
cd /u01/app/product/oracle/10.2.0/dbs/
scp initprod.ora
[email protected]:/u01/app/product/oracle/10.2.0/dbs/
-目标库
创建目录【切换到oracle用户--就不用更改目录所属用户的属性了】
su - oracle
mkdir /u02/oradata/ora10g/db2
mkdir /u01/app/admin/db2/adump -p
mkdir /u01/app/admin/db2/bdump -p
更改数据库启动文件
cd /u01/app/product/oracle/10.2.0/dbs/
cp initprod.ora initdb2.ora
更改db_name、dump所对应的新路径【这里为了方便直接批量替换】
vi initdb2.ora
:% s/prod/db2/g【一回车,就好了,方便吧】
差点忘了还有一步,很重要【更改RMAN传过来的文件所属用户属性,要不使用duplicate恢复的时候会出错】
cd /u01/app/flash_recovery_area/
chown -R oracle.oinstall PROD/
创建密码文件
orapwd file='/u01/app/product/oracle/10.2.0/dbs/orapwdb2' password=password
启动到nomount状态
SQL> startup nomount pfile='/u01/app/product/oracle/10.2.0/dbs/initdb2.ora';
开始恢复数据库【在源数据库上操作,暂没有在目标库上试过】
rman target / auxiliary
sys/lugeng@db2
RMAN>run
{
set until scn 504351;
duplicate target database to db2
DB_FILE_NAME_CONVERT=(prod,db2)
LOGFILE
'/u02/oradata/ora10g/db2/redo01.log' size 50m,
'/u02/oradata/ora10g/db2/redo02.log' size 50m,
'/u02/oradata/ora10g/db2/redo03.log' size 50m
open restricted;
}
{
set until scn 504351;
duplicate target database to db2
DB_FILE_NAME_CONVERT=(prod,db2)
LOGFILE
'/u02/oradata/ora10g/db2/redo01.log' size 50m,
'/u02/oradata/ora10g/db2/redo02.log' size 50m,
'/u02/oradata/ora10g/db2/redo03.log' size 50m
open restricted;
}
【看到上面那个号了吗?是不是很熟悉?没错,就是前面备份完后生成的。后面还有用处,接着往下盾...】
--注意了--【光标一直停在这儿,是不是会很长时间?本人就在这儿吃了不少的苦,希望看到此文章的人,不要再和我一样。错,是目标库没有退出sqlplus了。到目标库一看,果然有一窗口正在使用sqlplus登录中.quit。再到这儿,哈哈,齐刷刷地往下走...】
contents of Memory Script:
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script
删除源库带来的db link
sqlplus stradmin/stradmin
SQL> select * from global_name;
SQL> alter database rename global_name to test;
SQL> drop database link db2.net;
SQL> alter database rename global_name to db2.net;
创建连接到源库的db link
SQL> create database link prod.net connect to stradmin identified by stradmin using 'prod';
测试到源库的连通性
SQL> select instance_name from
v$instance@prod;
能出来prod就ok
SQL> select instance_name from
v$instance@db2;
能出来db2就Ok
mkdir /u01/app/admin/db2/cdump -p
mkdir /u01/app/admin/db2/udump -p