使用nid修改sid和dbname

如非必要,不建议在生产库上对dbid进行修改

1、修改dbid及dbname的影响
a、修改dbid
    等同于创建一个新的数据库,不同的是数据已经存在于数据文件。这是由dbid的唯一性决定的。
    修改之后所有之前的备份与归档日志将不可用,因为在恢复时会检测dbid,由于不匹配,则所有备份无效。
    修改之后需要使用open resetlogs打开数据库,一个新的incarnation会被创建,且sequence被置为1。
    修改之后且成功open的情形下,建议一致性关闭数据库,重启并做一个完整的备份。
b、修改dbname
    修改之后,无需使用open resetlogs打开数据库。(注dbname不具有唯一性,global name则具有唯一性)。
    修改之后,所有的备份即归档日志依旧可用。
    修改之后,需要修改pfile/spfile中对应的db_name参数以及重建相应的Oracle密码文件。
    如果需要使用旧的控制文件恢复数据库,应当使用修改之前的pfile/spfile以及密码文件启动数据库再进行恢复。
c、同时修改dbid及dbname
    如果同时修改,则是上述两种情形的综合,修改完毕后需要open resetlogs以及修改pfile/spifle,密码文件,全备数据库。


2、nid命令
[oracle@oratest ~]$ nid
DBNEWID: Release 11.2.0.3.0 - Production on Thu Dec 17 10:16:07 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Keyword     Description                    (Default)
----------------------------------------------------
TARGET      Username/Password              (NONE)
DBNAME      New database name              (NONE)
LOGFILE     Output Log                     (NONE)
REVERT      Revert failed change           NO
SETNAME     Set a new database name only   NO
APPEND      Append to output log           NO
HELP        Displays these messages        NO

    在执行nid命令时,该程序会校验当前数据库所有数据文件以及控制文件的头部信息,校验成功后提示是否要修改。
    如果使用了输出到日志文件logfile则不会出现修改提示。
    接下来nid将使用新的dbid(或者dbname)逐个修改控制文件,数据文件(包括只读文件,正常脱机文件)的头部。
    修改成功后自动关闭数据库并退出。
    注:对于只读文件,正常脱机文件本文未作测试。其次应确保数据库处于归档状态,可正常归档以及不存在需要recover的数据文件。

nid详细命令
     nid target=sys/password                                  #此方式是仅仅修改dbid
     nid target=/ dbname=new_dbname [setname=yes]             # / 表明连接到当前环境的sid,且使用操作系统认证
     nid target=sys/password dbname=new_dbname [setname=yes]  # setname=yes 仅仅修改数据库名字,如果省略,则两者同时修改
     nid target=sys/pwdd@conn_string dbname=new_dbname [setname=yes] #使用连接串连接到远程主机并修改

1)nid修改dbid
--查看当前dbid
SQL> conn /as sysdba
Connected.
SQL> select dbid from v$database;
      DBID
----------
1668473151

--启动db到mount 状态
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@oratest ~]$ nid target=sys/tina@tinadb

DBNEWID: Release 11.2.0.3.0 - Production on Thu Dec 17 10:02:06 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to database TINADB (DBID=1668473151)

Connected to server version 11.2.0

Control Files in database:
    /u01/oradata/tinadb/control01.ctl
    /u01/fast_recovery_area/tinadb/control02.ctl

Change database ID of database TINADB? (Y/[N]) => y

Proceeding with operation
Changing database ID from 1668473151 to 1669126943
    Control File /u01/oradata/tinadb/control01.ctl - modified
    Control File /u01/fast_recovery_area/tinadb/control02.ctl - modified
    Datafile /u01/oradata/tinadb/system01.db - dbid changed
    Datafile /u01/oradata/tinadb/sysaux01.db - dbid changed
    Datafile /u01/oradata/tinadb/undotbs01.db - dbid changed
    Datafile /u01/oradata/tinadb/users01.db - dbid changed
    Datafile /u01/oradata/tinadb/ts_tina01.db - dbid changed
    Datafile /u01/oradata/tinadb/temp01.db - dbid changed
    Datafile /u01/oradata/tinadb/temp02.db - dbid changed
    Control File /u01/oradata/tinadb/control01.ctl - dbid changed
    Control File /u01/fast_recovery_area/tinadb/control02.ctl - dbid changed
    Instance shut down

Database ID for database TINADB changed to 1669126943.
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 ID.
DBNEWID - Completed succesfully.

--重启db
SQL> startup;
ORACLE instance started.
Total System Global Area 2087780352 bytes
Fixed Size     2229944 bytes
Variable Size   520096072 bytes
Database Buffers 1560281088 bytes
Redo Buffers     5173248 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;
Database altered.

--查看修改后的值
SQL> select dbid from v$database;
      DBID
----------
1669126943


2)nid修改dbname
--查看当前dbname
SQL> select dbid,name,open_mode from v$database;
      DBID NAME      OPEN_MODE
---------- --------- --------------------
1669126943 TINADB    READ WRITE

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;   --mount状态下才能修改
ORACLE instance started.
Total System Global Area 2087780352 bytes
Fixed Size     2229944 bytes
Variable Size   520096072 bytes
Database Buffers 1560281088 bytes
Redo Buffers     5173248 bytes
Database mounted.

[oracle@oratest ~]$ nid target=sys/tina@tinadb dbname=tinadb2 setname=yes

DBNEWID: Release 11.2.0.3.0 - Production on Fri Dec 18 17:08:37 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to database TINADB (DBID=1669126943)

Connected to server version 11.2.0

Control Files in database:
    /u01/oradata/tinadb/control01.ctl
    /u01/fast_recovery_area/tinadb/control02.ctl

Change database name of database TINADB to TINADB2? (Y/[N]) => y

操作还算简单,但轻易也不要去生产做此类操作。

你可能感兴趣的:(oracle)