DBID是DataBase IDentifier的缩写,意思就是数据库的唯一标识符。这个DBID在数据文件头和控制文件都是存在的,可以用于标示数据文件的归属。 对于不同数据库来说,DBID应当不同,而db_name则可能是相同的.
关于dbid:
1,dbnewid 可以更改的内容
*数据库dbid
*数据库dbname
*同时更改数据库中的dbid和dbname
2.更改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,密码文件,全备数据库
3.更改dbid和dbname语法
*更改dbid
cmd> nid target=sys/password@test_db ---更改dbid必须定义一个具有sysdba权限的用户
*更改dbid同时更改dbname
cmd>nid target=sys/password@test_db dbname=name
*只更改dbname
cmd>nid target=sys/password@test_db dbname=name setname=yes
4.其他说明
不干净的关闭数据库后使用dbnewid更改数据库dbid会导致报错,有一个后动线程在使用.
方案1:使用nid修改改命令修改 dbname 及 及 dbid-- 不能修改为指定的 dbid
工作中不可避免地碰到需要修改 dbname 以及 dbid 的情形,如将数据库恢复到同一台机器的情形是其中之一。但 dbname 以及 dbid 是用于标识数据库的重要标志之一,尤其是 dbid,具有唯一性,因此对其修改应
慎重处理。本文描述了修改 dbname 以及 dbid 的步骤并给出示例。nid 工具执行的命令实际也是调用 DBMS_BACKUP_RESTORE 包相应的存储过程实现的。

修改步骤:
a、全备数据库,如果是热备(rman or os)应确保所有的归档日志以及联机日志可用
b、删除 dbconsole([ID 863800.1]有此要求,如用到 dbconsole,应考虑按此操作)
c、启动需要修改的数据库到 mount 状态(startup mount)
d、如果使用 spfile 文件启动数据库,备份 spfile 文件到 pfile 用于后续修改 db_name
e、发布 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] #使用连接串连接到远程主机并修改
f、修改 Oracle 参数文件 pfile(使用先前从 spfile 备份的)中的参数 db_name,如果仅仅修改 dbid,跳过此步骤
g、使用新的参数文件 pfile 启动到 mount 状态(如果修改了 dbname,如果仅仅是 dbid,则直接使用原来的 pfile 或 spfile 启动)
h、使用 open resetlogs 方式打开数据库(修改非 dbid,直接打开即可)
i、重建当前数据库的 Oralce 密码文件及将 pfile 文件转换成 spfile 文件
j、修改相应的监听器的配值,包括 listener.ora 以及 tnsnames.ora
k、修改全局 dbname,如果有用到的话。ALTER DATABASE RENAME GLOBAL_NAME TO <newname>.<domain>;
l、重建 dbconsole $ emca -config dbcontrol db -repos recreate
m、全备数据库

1. 修改dbid

1.1 nid命令解析

[oracle@oracle dbs]$ nid

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jan 12 00:11:55 2021

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

1.2.修改dbid

s```sql
hutdown immediate
startup mount
SQL> select dbid,name,open_mode from v$database
2 ;

  DBID NAME      OPEN_MODE

1583927885 ORCL MOUNTED

[oracle@oracle dbs]$ nid target=sys/123456

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jan 12 00:30:32 2021

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

Connected to database ORCL (DBID=1583927885)

Connected to server version 11.2.0

Control Files in database:
/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/fast_recovery_area/orcl/control02.ctl

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

Proceeding with operation
Changing database ID from 1583927885 to 1589396777
Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - modified
Datafile /u01/app/oracle/oradata/orcl/system01.db - dbid changed
Datafile /u01/app/oracle/oradata/orcl/sysaux01.db - dbid changed
Datafile /u01/app/oracle/oradata/orcl/undotbs01.db - dbid changed
Datafile /u01/app/oracle/oradata/orcl/users01.db - dbid changed
Datafile /u01/app/oracle/oradata/orcl/temp01.db - dbid changed
Control File /u01/app/oracle/oradata/orcl/control01.ctl - dbid changed
Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - dbid changed
Instance shut down

Database ID for database ORCL changed to 1589396777.
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.


## 1.3.使用open resetlogs启动数据库
```sql
SQL> startup mount
ORACLE instance started.

Total System Global Area  776646656 bytes
Fixed Size                  2257272 bytes
Variable Size             507514504 bytes
Database Buffers          264241152 bytes
Redo Buffers                2633728 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;

Database altered.

SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   1
Current log sequence           1

2.修改dbname

2.1全备数据库

rman backup

2.2备份spfile到pfile

create pfile='/tmp/aaa.ora' from spfile;

2.3将数据库置于mount状态

startup mount

2.4查看当前数据的dbid和dbname

SQL> select dbid,name,open_mode from v$database;

      DBID NAME      OPEN_MODE
---------- --------- --------------------
1589396777 ORCL      MOUNTED

2.5 修改dbname

nid target=sys/123456 dbname=COCO setname=yes
[oracle@oracle dbs]$ nid target=sys/123456 dbname=COCO setname=yes

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jan 12 01:03:02 2021

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

Connected to database ORCL (DBID=1589396777)

Connected to server version 11.2.0

Control Files in database:
    /u01/app/oracle/oradata/orcl/control01.ctl
    /u01/app/oracle/fast_recovery_area/orcl/control02.ctl

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

Proceeding with operation
Changing database name from ORCL to COCO
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/orcl/system01.db - wrote new name
    Datafile /u01/app/oracle/oradata/orcl/sysaux01.db - wrote new name
    Datafile /u01/app/oracle/oradata/orcl/undotbs01.db - wrote new name
    Datafile /u01/app/oracle/oradata/orcl/users01.db - wrote new name
    Datafile /u01/app/oracle/oradata/orcl/temp01.db - wrote new name
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - wrote new name
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - wrote new name
    Instance shut down

Database name changed to COCO.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.

2.6修改pfile

db_name=coco

2.7使用pifle启动数据库

SQL> startup mount pfile='aaa.ora';
ORACLE instance started.

Total System Global Area  776646656 bytes
Fixed Size                  2257272 bytes
Variable Size             507514504 bytes
Database Buffers          264241152 bytes
Redo Buffers                2633728 bytes
Database mounted.
SQL> alter database open; 

Database altered.

2.8查看验证当前数据的dbid和dbname

SQL> select dbid,name,open_mode from v$database;

      DBID NAME      OPEN_MODE
---------- --------- --------------------
1589396777 COCO      READ WRITE
--校验修伽后的状态,dbid 未发生变化,但 dbname 已经被修改

2.9重建spfile

create spfile from pfile='aaa.ora';

3.同时修改 dbname 以及 dbid

3.1全备数据库

rman backup

3.2备份spfile到pfile

create pfile='/tmp/aaa.ora' from spfile;

3.3将数据库置于mount状态

startup mount

3.4查看当前数据的dbid和dbname

SQL> select dbid,name,open_mode from v$database;

      DBID NAME      OPEN_MODE
---------- --------- --------------------
1589396777 COCO      MOUNTED

3.5 修改dbname和dbid

nid target=/ dbname=CYB

[oracle@oracle ~]$ nid target=/ dbname=CYB

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jan 12 01:22:13 2021

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

Connected to database COCO (DBID=1589396777)

Connected to server version 11.2.0

Control Files in database:
    /u01/app/oracle/oradata/orcl/control01.ctl
    /u01/app/oracle/fast_recovery_area/orcl/control02.ctl

Change database ID and database name COCO to CYB? (Y/[N]) => y

Proceeding with operation
Changing database ID from 1589396777 to 2991861189
Changing database name from COCO to CYB
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - modified
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - modified
    Datafile /u01/app/oracle/oradata/orcl/system01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/sysaux01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/undotbs01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/users01.db - dbid changed, wrote new name
    Datafile /u01/app/oracle/oradata/orcl/temp01.db - dbid changed, wrote new name
    Control File /u01/app/oracle/oradata/orcl/control01.ctl - dbid changed, wrote new name
    Control File /u01/app/oracle/fast_recovery_area/orcl/control02.ctl - dbid changed, wrote new name
    Instance shut down

Database name changed to CYB.
Modify parameter file and generate a new password file before restarting.
Database ID for database CYB changed to 2991861189.
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.

3.6修改pfile

db_name=cyb

3.7使用pifle启动数据库

SQL> startup mount pfile='aaa.ora';
ORACLE instance started.

Total System Global Area  776646656 bytes
Fixed Size                  2257272 bytes
Variable Size             507514504 bytes
Database Buffers          264241152 bytes
Redo Buffers                2633728 bytes
Database mounted.
SQL> alter database open
  2  ;
alter database open
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;
Database altered.

3.8查看验证当前数据的dbid和dbname

SQL> select dbid,name,open_mode from v$database;

      DBID NAME      OPEN_MODE
---------- --------- --------------------
2991861189 CYB       READ WRITE
--校验修伽后的状态,dbid 未发生变化,但 dbname 已经被修改

3.9重建spfile

create spfile from pfile;

Related Posts