您好,欢迎访问一九零五行业门户网

使用dbms_backup_restore包修改dbname及dbid

修改dbname以及dbid通常在使用rman还原到异机之后需要更改dbname以及dbid的情形。对于这个修改我们可以借助于命令行下的nid工具来完成。同时也可以直接调用api来实现。本文即是通过dbms_backup_restore方式来修改dbname及dbid,供大家参考。 有关使用nid方式
修改dbname以及dbid通常在使用rman还原到异机之后需要更改dbname以及dbid的情形。对于这个修改我们可以借助于命令行下的nid工具来完成。同时也可以直接调用api来实现。本文即是通过dbms_backup_restore方式来修改dbname及dbid,供大家参考。
有关使用nid方式修改dbname及dbid,请参考:使用nid命令修改 db name 及 dbid
1、修改dbid及dbname的步骤 
2、实战演习
robin@szdb:~/dba_scripts/custom/sql> export oracle_sid=es0481robin@szdb:~/dba_scripts/custom/sql> sqlplus / as sysdbasql*plus: release 10.2.0.3.0 - production on sat mar 29 20:18:28 2014copyright (c) 1982, 2006, oracle. all rights reserved.connected to:oracle database 10g release 10.2.0.3.0 - 64bit productionsys@es0481> shutdown immediate;sys@es0481> startup open read only;sys@es0481> select name,dbid from v$database;name dbid--------- ----------es0481 123456sys@es0481> @chg_dbname_dbidpl/sql procedure successfully completed.old_name------------------------------------------------------es0481enter the new database name:es0480enter the new database id:654321pl/sql procedure successfully completed.pl/sql procedure successfully completed.convert es0481(123456) to es0480(654321)pl/sql procedure successfully completed.controlfile:=> change name:1=> change dbid:1datafile: /u02/database/es0481/oradata/syses0481.dbf=> skipped:0=> change name:1=> change dbid:1datafile: /u02/database/es0481/undo/undotbses0481.dbf=> skipped:0=> change name:1=> change dbid:1 .................datafile: /u02/database/es0481/temp/es0481_tempes0481.dbf=> skipped:0=> change name:1=> change dbid:1pl/sql procedure successfully completed.sys@es0481> create pfile from spfile;file created.sys@es0481> ho cat $oracle_home/dbs/inites0481.ora |sed s/db_name='es0481'/db_name='es0480'/>$oracle_home/dbs/inites0480.orasys@es0481> shutdown immediate;sys@es0481> exitdisconnected from oracle database 10g release 10.2.0.3.0 - 64bit productionrobin@szdb:~/dba_scripts/custom/sql> export oracle_sid=es0480robin@szdb:~/dba_scripts/custom/sql> sqlplus / as sysdbaidle> startup pfile=/users/oracle/orahome10g/dbs/inites0480.ora mount;oracle instance started.total system global area 599785472 bytesfixed size 2074568 bytesvariable size 167774264 bytesdatabase buffers 423624704 bytesredo buffers 6311936 bytesdatabase mounted.idle> alter database open resetlogs;database altered.-- author : leshami-- blog : http://blog.csdn.net/leshamiidle> create spfile from pfile='/users/oracle/orahome10g/dbs/inites0480.ora';file created.idle> startup force;idle> select name,dbid from v$database;name dbid--------- ----------es0480 654321
3、脚本chg_dbname_dbid.sql
--该脚本从网上整理而来--该脚本可以修改dbname,以及dbid,或者两者同时修改--该脚本在10g下测试ok,11g下有待测试robin@szdb:~/dba_scripts/custom/sql> more chg_dbname_dbid.sql var old_name varchar2(20)var old_dbid numbervar new_name varchar2(20)var new_dbid numberexec select name, dbid - into :old_name,:old_dbid - from v$databaseprint old_nameaccept new_name prompt enter the new database name:accept new_dbid prompt enter the new database id:exec :new_name:='&&new_name'exec :new_dbid:=&&new_dbidset serveroutput onexec dbms_output.put_line('convert '||:old_name|| - '('||to_char(:old_dbid)||') to '||:new_name|| - '('||to_char(:new_dbid)||')') declare v_chgdbid binary_integer; v_chgdbname binary_integer; v_skipped binary_integer;begin dbms_backup_restore.nidbegin(:new_name, :old_name,:new_dbid,:old_dbid,0,0,10); dbms_backup_restore.nidprocesscf( v_chgdbid,v_chgdbname); dbms_output.put_line('controlfile: '); dbms_output.put_line(' => change name:' ||to_char(v_chgdbname)); dbms_output.put_line(' => change dbid:' ||to_char(v_chgdbid)); for i in (select file#,name from v$datafile) loop dbms_backup_restore.nidprocessdf(i.file#,0, v_skipped,v_chgdbid,v_chgdbname); dbms_output.put_line('datafile: '||i.name); dbms_output.put_line(' => skipped:' ||to_char(v_skipped)); dbms_output.put_line(' => change name:' ||to_char(v_chgdbname)); dbms_output.put_line(' => change dbid:' ||to_char(v_chgdbid)); end loop; for i in (select file#,name from v$tempfile) loop dbms_backup_restore.nidprocessdf(i.file#,1, v_skipped,v_chgdbid,v_chgdbname); dbms_output.put_line('datafile: '||i.name); dbms_output.put_line(' => skipped:' ||to_char(v_skipped)); dbms_output.put_line(' => change name:' ||to_char(v_chgdbname)); dbms_output.put_line(' => change dbid:' ||to_char(v_chgdbid)); end loop; dbms_backup_restore.nidend;end;/
更多参考
有关oracle rac请参考
有关oracle 网络配置相关基础以及概念性的问题请参考:
有关基于用户管理的备份和备份恢复的概念请参考
有关rman的备份恢复与管理请参考
有关oracle体系结构请参考
其它类似信息

推荐信息