修改dbname以及dbid通常在使用RMAN还原到异机之后需要更改dbname以及dbid的情形。对于这个修改我们可以借助于命令行下的nid工具来完成。同时也可以直接调用API来实现。本文即是通过dbms_backup_restore方式来修改dbname及dbid,供大家参考。
有关使用nid方式修改dbname及dbid,请参考:使用nid命令修改 db name 及 dbid
1、修改dbid及dbname的步骤
a、一致性关闭数据库并启动数据库到read only状态(需要调用dbms_backup_restore,因此要open数据库)
b、调用脚本修改dbname或者dbid(根据提示输入)
c、修改spfile或pfile中的db_name的值,如果仅改变dbid,此步骤可忽略
d、以open resetlogs方式打开数据库
2、实战演习
robin@SZDB:~/dba_scripts/custom/sql> export ORACLE_SID=ES0481
robin@SZDB:~/dba_scripts/custom/sql> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Sat Mar 29 20:18:28 2014
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
sys@ES0481> shutdown immediate;
sys@ES0481> startup open read only;
sys@ES0481> select name,dbid from v$database;
NAME DBID
--------- ----------
ES0481 123456
sys@ES0481> @chg_dbname_dbid
PL/SQL procedure successfully completed.
OLD_NAME
------------------------------------------------------
ES0481
Enter the new Database Name:ES0480
Enter the new Database ID:654321
PL/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:1
DataFile: /u02/database/ES0481/oradata/sysES0481.dbf
=> Skipped:0
=> Change Name:1
=> Change DBID:1
DataFile: /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:1
PL/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.ora
sys@ES0481> shutdown immediate;
sys@ES0481> exit
Disconnected from Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
robin@SZDB:~/dba_scripts/custom/sql> export ORACLE_SID=ES0480
robin@SZDB:~/dba_scripts/custom/sql> sqlplus / as sysdba
idle> startup pfile=/users/oracle/OraHome10g/dbs/initES0480.ora mount;
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 2074568 bytes
Variable Size 167774264 bytes
Database Buffers 423624704 bytes
Redo Buffers 6311936 bytes
Database mounted.
idle> alter database open resetlogs;
Database altered.
-- Author : Leshami
-- Blog : http://blog.csdn.net/leshami
idle> 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 number
var new_name varchar2(20)
var new_dbid number
exec select name, dbid -
into :old_name,:old_dbid -
from v$database
print old_name
accept 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_dbid
set serveroutput on
exec 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请参考
使用crs_setperm修改RAC资源的所有者及权限
使用crs_profile管理RAC资源配置文件
RAC 数据库的启动与关闭
再说 Oracle RAC services
Services in Oracle Database 10g
Migrate datbase from single instance to Oracle RAC
Oracle RAC 连接到指定实例
Oracle RAC 负载均衡测试(结合服务器端与客户端)
Oracle RAC 服务器端连接负载均衡(Load Balance)
Oracle RAC 客户端连接负载均衡(Load Balance)
ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
ORACLE RAC 监听配置 (listener.ora tnsnames.ora)
配置 RAC 负载均衡与故障转移
CRS-1006 , CRS-0215 故障一例
基于Linux (RHEL 5.5) 安装Oracle 10g RAC
使用 runcluvfy 校验Oracle RAC安装环境
有关Oracle 网络配置相关基础以及概念性的问题请参考:
配置非默认端口的动态服务注册
配置sqlnet.ora限制IP访问Oracle
Oracle 监听器日志配置与管理
设置 Oracle 监听器密码(LISTENER)
配置ORACLE 客户端连接到数据库
有关基于用户管理的备份和备份恢复的概念请参考
Oracle 冷备份
Oracle 热备份
Oracle 备份恢复概念
Oracle 实例恢复
Oracle 基于用户管理恢复的处理
SYSTEM 表空间管理及备份恢复
SYSAUX表空间管理及恢复
Oracle 基于备份控制文件的恢复(unsing backup controlfile)
有关RMAN的备份恢复与管理请参考
RMAN 概述及其体系结构
RMAN 配置、监控与管理
RMAN 备份详解
RMAN 还原与恢复
RMAN catalog 的创建和使用
基于catalog 创建RMAN存储脚本
基于catalog 的RMAN 备份与恢复
RMAN 备份路径困惑
使用RMAN实现异机备份恢复(WIN平台)
使用RMAN迁移文件系统数据库到ASM
linux 下RMAN备份shell脚本
使用RMAN迁移数据库到异机
有关ORACLE体系结构请参考
Oracle 表空间与数据文件
Oracle 密码文件
Oracle 参数文件
Oracle 联机重做日志文件(ONLINE LOG FILE)
Oracle 控制文件(CONTROLFILE)
Oracle 归档日志
Oracle 回滚(ROLLBACK)和撤销(UNDO)
Oracle 数据库实例启动关闭过程
Oracle 10g SGA 的自动化管理
Oracle 实例和Oracle数据库(Oracle体系结构)