在RAC中用NID修改数据库名称

现在数据库的名称是:dcw要改成yutian
SQL> show parameter name


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      dcw
db_unique_name                       string      dcw
global_names                         boolean     FALSE
instance_name                        string      yutian1
lock_name_space                      string
log_file_name_convert                string
service_names    


改名推荐一个好工具,dbnewid,只需一行命令,即可轻松搞定,操作如下(注意nid执行时数据库必须处于mount状态):




在RAC中用NID修改数据库名称
在rac中修改db_name的步骤与单实例步骤差不多,主要是要修改一些与cluster相关的参数。
停止所有实例,然后把其中一个实例启动到mount状态下:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  2083368 bytes
Variable Size             121636312 bytes
Database Buffers          155189248 bytes
Redo Buffers                6303744 bytes
Database mounted.


尝试用NID修改数据库名称:
[oracle@yutian1 ~]$ nid target=sys/oracle dbname=yutian logfile=/home/oracle/nid1.log
查看日志:
[oracle@yutian1 ~]$ more nid1.log


DBNEWID: Release 10.2.0.4.0 - Production on Fri Apr 3 14:01:06 2015


Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to database DCW (DBID=3749110133)


NID-00120: Database should be mounted exclusively




Change of database name failed during validation - database is intact.
DBNEWID - Completed with validation errors.


发现有报错,这个因为当前数据库是rac,需要修改cluster_database=false,这也就是用nid修改rac数据库名称与修改单实例数据库名称的一个主要区别。  


SQL> alter system set cluster_database=false scope=spfile;


System altered.


SQL> shutdown immediate
ORA-01109: database not open




Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  2083368 bytes
Variable Size             121636312 bytes
Database Buffers          155189248 bytes
Redo Buffers                6303744 bytes
Database mounted.
SQL> exit


[oracle@yutian1 ~]$ nid target=sys/oracle dbname=yutian logfile=/home/oracle/nid1.log
[oracle@yutian1 ~]$ more nid1.log


DBNEWID: Release 10.2.0.4.0 - Production on Fri Apr 3 14:05:22 2015


Copyright (c) 1982, 2007, Oracle.  All rights reserved.


Connected to database DCW (DBID=3749110133)


Connected to server version 10.2.0


Control Files in database:
    +DATA/control01.ctl
    +DATA/control02.ctl


Changing database ID from 3749110133 to 2643537571
Changing database name from DCW to YUTIAN
    Control File +DATA/control01.ctl - modified
    Control File +DATA/control02.ctl - modified
    Datafile +DATA/system01.dbf - dbid changed, wrote new name
    Datafile +DATA/undotbs01.dbf - dbid changed, wrote new name
    Datafile +DATA/sysaux01.dbf - dbid changed, wrote new name
    Datafile +DATA/dcw/datafile/users.262.876051821 - dbid changed, wrote new name
    Datafile +DATA/undotbs02.dbf - dbid changed, wrote new name
    Datafile +DATA/temp02.dbf - dbid changed, wrote new name
    Control File +DATA/control01.ctl - dbid changed, wrote new name
    Control File +DATA/control02.ctl - dbid changed, wrote new name
    Instance shut down


Database name changed to YUTIAN.
Modify parameter file and generate a new password file before restarting.
Database ID for database YUTIAN changed to 2643537571.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


从日志可以看到,数据库名称修改成功。 
重新把cluster_database设置为true,并把db_name参数修改为新的名称:
[oracle@yutian1 ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.4.0 - Production on Fri Apr 3 14:07:32 2015


Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.


Connected to an idle instance.


SQL> startup mount
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  2083368 bytes
Variable Size             121636312 bytes
Database Buffers          155189248 bytes
Redo Buffers                6303744 bytes
ORA-01103: database name 'YUTIAN' in control file is not 'DCW'




SQL> alter system set db_name=YUTIAN scope=spfile;


System altered.


SQL> alter system set cluster_database=true scope=spfile;


System altered.


SQL> shutdown immediate
ORA-01507: database not mounted




ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.


Total System Global Area  285212672 bytes
Fixed Size                  2083368 bytes
Variable Size             121636312 bytes
Database Buffers          155189248 bytes
Redo Buffers                6303744 bytes
Database mounted.
最后在打开的时候open resetlogs即可。  
SQL> alter database open resetlogs;


Database altered.


把rac环境的其他节点也启动,至此,dbname修改完成。 


如果nid修改时报错: 
ID-00135: There are 1 active threads 


则表示有活动进程,可能原因是: 
1、上次数据库不是干净关闭的 
2、有其他人在操作这个数据库 


最简单的办法是停止监听,然后把数据库干净关闭再做操作。


 将其他信息注册到CRS里
[oracle@yutian1 ~]$ crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora.dcw.db     application    OFFLINE   OFFLINE
ora....n1.inst application    OFFLINE   OFFLINE
ora....n2.inst application    OFFLINE   OFFLINE
ora....SM1.asm application    ONLINE    ONLINE    yutian1
ora....N1.lsnr application    ONLINE    ONLINE    yutian1
ora....an1.gsd application    ONLINE    ONLINE    yutian1
ora....an1.ons application    ONLINE    ONLINE    yutian1
ora....an1.vip application    ONLINE    ONLINE    yutian1
ora....SM2.asm application    ONLINE    ONLINE    yutian2
ora....N2.lsnr application    ONLINE    ONLINE    yutian2
ora....an2.gsd application    ONLINE    ONLINE    yutian2
ora....an2.ons application    ONLINE    ONLINE    yutian2
ora....an2.vip application    ONLINE    ONLINE    yutian2
[oracle@yutian1 ~]$ srvctl add database -d yutian -o $ORACLE_HOME -p +DATA/spfileyutian.ora
[oracle@yutian1 ~]$ srvctl add instance -d yutian -i yutian1 -n yutian1
[oracle@yutian1 ~]$ srvctl add instance -d yutian -i yutian2 -n yutian2


这里并没有启动,因为我们的服务是刚添加上来的,还没有同步。 我们启动一下就ok了。
[oracle@yutian1 ~]$ crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora.dcw.db     application    OFFLINE   OFFLINE
ora....n1.inst application    OFFLINE   OFFLINE
ora....n2.inst application    OFFLINE   OFFLINE
ora.yutian.db  application    OFFLINE   OFFLINE
ora....n1.inst application    OFFLINE   OFFLINE
ora....n2.inst application    OFFLINE   OFFLINE
ora....SM1.asm application    ONLINE    ONLINE    yutian1
ora....N1.lsnr application    ONLINE    ONLINE    yutian1
ora....an1.gsd application    ONLINE    ONLINE    yutian1
ora....an1.ons application    ONLINE    ONLINE    yutian1
ora....an1.vip application    ONLINE    ONLINE    yutian1
ora....SM2.asm application    ONLINE    ONLINE    yutian2
ora....N2.lsnr application    ONLINE    ONLINE    yutian2
ora....an2.gsd application    ONLINE    ONLINE    yutian2
ora....an2.ons application    ONLINE    ONLINE    yutian2
ora....an2.vip application    ONLINE    ONLINE    yutian2


修改instance 和 asm 之间的依赖关系:
[oracle@yutian1 ~]$ srvctl modify instance -d yutian -i yutian1 -s +ASM1
[oracle@yutian1 ~]$ srvctl modify instance -d yutian -i yutian2 -s +ASM2
[oracle@yutian1 ~]$ srvctl start database -d yutian
[oracle@yutian1 ~]$ crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora.dcw.db     application    OFFLINE   OFFLINE
ora....n1.inst application    OFFLINE   OFFLINE
ora....n2.inst application    OFFLINE   OFFLINE
ora.yutian.db  application    ONLINE    ONLINE    yutian1
ora....n1.inst application    ONLINE    ONLINE    yutian1
ora....n2.inst application    ONLINE    ONLINE    yutian2
ora....SM1.asm application    ONLINE    ONLINE    yutian1
ora....N1.lsnr application    ONLINE    ONLINE    yutian1
ora....an1.gsd application    ONLINE    ONLINE    yutian1
ora....an1.ons application    ONLINE    ONLINE    yutian1
ora....an1.vip application    ONLINE    ONLINE    yutian1
ora....SM2.asm application    ONLINE    ONLINE    yutian2
ora....N2.lsnr application    ONLINE    ONLINE    yutian2
ora....an2.gsd application    ONLINE    ONLINE    yutian2
ora....an2.ons application    ONLINE    ONLINE    yutian2
ora....an2.vip application    ONLINE    ONLINE    yutian2
[oracle@yutian1 ~]$


删除老的数据库信息:
[oracle@yutian1 ~]$ srvctl remove database -d dcw
Remove the database dcw? (y/[n]) y
[oracle@yutian1 ~]$ crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora.yutian.db  application    ONLINE    ONLINE    yutian1
ora....n1.inst application    ONLINE    ONLINE    yutian1
ora....n2.inst application    ONLINE    ONLINE    yutian2
ora....SM1.asm application    ONLINE    ONLINE    yutian1
ora....N1.lsnr application    ONLINE    ONLINE    yutian1
ora....an1.gsd application    ONLINE    ONLINE    yutian1
ora....an1.ons application    ONLINE    ONLINE    yutian1
ora....an1.vip application    ONLINE    ONLINE    yutian1
ora....SM2.asm application    ONLINE    ONLINE    yutian2
ora....N2.lsnr application    ONLINE    ONLINE    yutian2
ora....an2.gsd application    ONLINE    ONLINE    yutian2
ora....an2.ons application    ONLINE    ONLINE    yutian2
ora....an2.vip application    ONLINE    ONLINE    yutian2



















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值