阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用NID修改DBID和DBNAME实验

114次阅读
没有评论

共计 23738 个字符,预计需要花费 60 分钟才能阅读完成。

在 Oracle 中,DBID 和 DBNAME 是两个低调但又是及其重要的对象。作为标记信息,DBID 和 DBNAME 广泛的出现在参数文件、密码文件、数据文件和日志文件中,更有甚者在备份集合归档日志中。笔者看过一位前辈的文章中,强调称职 DBA 应该将管理数据库的 DBID 牢记于心。

一般情况下,已经创建好的数据库是不需要修改 DBID 和 DBNAME 信息的。因为,修改这些信息意味着 Oracle 关键信息的变化,和大量备份数据的废止。如果需要进行变更,一定要按照固定的操作程序,将对应的数据内容修改完好。

1、修改 DBID 和 DBNAME,是一个大事情

DBID 是一个十进制数字,Oracle 依据唯一性算法计算得到作为内部数据库的标记信息。在数据文件、日志和备份集合中,DBID 都是作为重要标记进行使用。DBNAME 是用户设置的项目内容,分布在密码文件、参数文件和数据文件中。如果存在修改 DBID 的情况,Online Redo Log 需要进行 ResetLog 操作,原有的归档和备份文件都需要废除失效。

对修改 DBID 和 DBNAME 操作,我们一定要明确后续调整和修复的范围动作。如果修改 DBID,所有之前进行的备份和归档日志就没有效用了。整个过程就和全新创建数据库(除了数据文件存在)没有差异。我们启动数据库 Open 的时候,就需要 resetlogs 模式启动,刷新废除所有的 online redo logs 组,开启一个新的 Sequence 序列。在投产条件下,如果我们修改了 DBID,就必须立即进行数据库备份动作,避免数据库裸奔。

如果修改了 DBNAME,问题简单一些,是不需要我们 resetlogs 的。之前的备份集合和归档日志还是可以继续使用。DBNAME 修改要求手工的在 SPFile 或者 Pfile 中修改初始化参数,密码文件也需要进行修改。注意:对应控制文件的备份,如果希望使用只前备份的控制文件恢复,就需要使用之前的参数文件进行启动。

#

文件信息

受影响参数

NID 是否处理

1

Password File

DBNAME

2

Parameter File

DBNAME

3

Data File

DBNAMEDBID

 

4

Online Redo Log

DBID

 

5

Archived Redo Log

DBID

6

Backup Set

DBID

7

Control File

DBIDDBNAME

 

8

Oracle NET File

DBNAME

9

DBConsole

DBIDDBNAME

下面,通过一系列的实验,演示如何使用 Oracle NID 工具进行 DBID 和 DBNAME 修改。

2、同时修改 DBID 和 DBNAME

当前笔者使用 11.2.0.4 数据库进行测试,数据库处在归档模式下。当前数据库名称为 MYTEDB,对应的 DBID 如下所示。

SQL> select * from v$version;

BANNER

——————————————————————————–

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

PL/SQL Release 11.2.0.4.0 – Production

CORE    11.2.0.4.0      Production

TNS for Linux: Version 11.2.0.4.0 – Production

NLSRTL Version 11.2.0.4.0 – Production

SQL> select dbid, name from v$database;

      DBID NAME

———- ———

2764682050 MYTEDB

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival            Enabled

首先,确认备份和归档日志情况。查看环境变量信息。

[oracle@MYTElife ~]$ env | grep ORA

ORACLE_SID=MYTEdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

[oracle@MYTElife ~]$ cd $ORACLE_HOME/bin

[oracle@MYTElife bin]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1/bin

如果配置了 DBConsole,需要删除 DBConsole 对象。之后完全关闭,重新启动进行 mount 状态。同时,确认一下 Oracle Net 目录中三个文件:tnsnames.ora、listener.ora 和 sqlnet.ora,其中包括 DBNAME 项目,都需要修改。

[oracle@MYTElife bin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:45:58 2016

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

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

进入 $ORACLE_HOME/bin 文件夹,调用 nid 命令。

[oracle@MYTElife bin]$ nid target=sys/oracle dbname=testdb

DBNEWID: Release 11.2.0.4.0 – Production on Wed Oct 19 18:48:44 2016

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

Connected to database MYTEDB (DBID=2764682050)

Connected to server version 11.2.0

Control Files in database:

    /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl

    /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl

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

Proceeding with operation

Changing database ID from 2764682050 to 2708979596

Changing database name from MYTEDB to TESTDB

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – modified

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – modified

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_system_bw773xok_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_sysaux_bw773xpr_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_undotbs1_bw773xqo_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_users_bw773xrv_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_MYTEdev_bw8xbqrz_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_inttestt_bw8xdnkt_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_epssite_by19vtnh_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_temp_bw776mow_.tm – dbid changed, wrote new name

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – dbid changed, wrote new name

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – dbid changed, wrote new name

    Instance shut down

Database name changed to TESTDB.

Modify parameter file and generate a new password file before restarting.

Database ID for database TESTDB changed to 2708979596.

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.

在提示信息中,可以清晰看到 Oracle NID 名称将数据文件中的 DBID 和 Name 信息修改,并且在提示中提醒了需要修改内容。

在 alert log 中,我们看到了 DBID 和 Name 的变化过程。

Wed Oct 19 18:49:04 2016

*** DBNEWID utility started ***

DBID will be changed from 2764682050 to new DBID of 2708979596 for database MYTEDB

DBNAME will be changed from MYTEDB to new DBNAME of TESTDB

Starting datafile conversion

Datafile conversion complete

Database name changed to TESTDB.

Modify parameter file and generate a new password file before restarting.

Database ID for database TESTDB changed to 2708979596.

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open with RESETLOGS option.

Succesfully changed database name and ID.

*** DBNEWID utility finished succesfully ***

下面,需要修改 Spfile 中的 dbname 信息。方法和以前用到的相同,都是通过 spfile 生成 pfile,手工修改其中的 db_name 参数。

[oracle@MYTElife trace]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:51:26 2016

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> create pfile from spfile;

File created.

修改生成 initMYTEdb.ora 文件。

[oracle@MYTElife trace]$ cd $ORACLE_HOME/dbs

[oracle@MYTElife dbs]$ ls -l

total 9544

-rw-r—– 1 oracle oinstall    1544 Oct 19 18:49 hc_MYTEdb.dat

-rw-r–r– 1 oracle oinstall    2851 May 15  2009 init.ora

-rw-r–r– 1 oracle oinstall    1092 Oct 19 18:51 initMYTEdb.ora

-rw-r—– 1 oracle oinstall      24 Aug  7  2015 lkMYTEDB

[oracle@MYTElife dbs]$ vi initMYTEdb.ora 

MYTEdb.__large_pool_size=184549376

*.db_create_file_dest=’/u01/app/oracle/oradata’

*.db_domain=”

*.db_name=’testdb’

*.db_recovery_file_dest=’/u01/app/oracle/fast_recovery_area’

*.db_recovery_file_dest_size=10737418240

如果使用 ASM,还要修改 ASM 文件名。之后就可以使用新的 testdb 来启动。

[oracle@MYTElife dbs]$ export ORACLE_SID=testdb

[oracle@MYTElife dbs]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:54:26 2016

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup mount pfile=initMYTEdb.ora       

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

Open 数据库时候,由于是一个全新的 DBID,所以需要 resetlogs 模式。在日志上,我们的确也看到了 Oracle 删除原有 online redo log 动作的过程。

SQL> alter database open resetlogs;

Database altered.

–alert log 信息

Wed Oct 19 18:56:59 2016

alter database open resetlogs

RESETLOGS after complete recovery through change 1719246

Resetting resetlogs activation ID 2764689218 (0xa4c9cf42)

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_1_bw77672y_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_1_bw7767d4_.log

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_2_bw776938_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_2_bw7769cc_.log

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_3_bw776cck_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_3_bw776cmv_.log

Wed Oct 19 18:57:03 2016

Setting recovery target incarnation to 2

重新生成 spfile。

SQL> create spfile from memory;

File created.

创建密码文件,对应新的 testdb 的数据库名称。

[oracle@MYTElife dbs]$ ls -l | grep orapw

-rw-r—– 1 oracle oinstall    1536 Aug  7  2015 orapwMYTEdb

[oracle@MYTElife dbs]$ orapwd file=orapwtestdb password=oracle entries=10 force=y

[oracle@MYTElife dbs]$ ls -l | grep orapw

-rw-r—– 1 oracle oinstall    1536 Aug  7  2015 orapwMYTEdb

-rw-r—– 1 oracle oinstall    2560 Oct 19 19:02 orapwtestdb

查看监听器状态,修改 Oracle NET 文件。

[oracle@MYTElife dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 – Production on 19-OCT-2016 19:09:51

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

————————

Alias                    LISTENER

(篇幅原因,有省略……)

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Services Summary…

Service “testdb” has 1 instance(s).

  Instance “testdb”, status READY, has 1 handler(s) for this service…

Service “testdbXDB” has 1 instance(s).

  Instance “testdb”, status READY, has 1 handler(s) for this service…

The command completed successfully

对应新生成的 dbid 和 dbname 信息。

SQL> select dbid, name from v$database;

      DBID NAME

———- ———

2708979596 TESTDB

最后,如果使用了 global_name 参数,也要进行修改。

注意:如果是 Windows 环境的话,DBNAME 修改,在 Services 列表中需要重新生成服务。另外,修改 DBID 之后,原有的所有备份都失效了,需要重新备份。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2016-10/136568p2.htm

3、单独修改 DBID 情况

如果是单独修改 DBID 的情况呢?需要修改的范围略小一些。

[Oracle@MYTElife admin]$ env | grep ORA

ORACLE_SID=testdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

启动数据库到 mount 状态,启动 nid 进行修改。

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            872417904 bytes

Database Buffers        2650800128 bytes

Redo Buffers              15405056 bytes

Database mounted.

SQL> quit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@MYTElife dbs]$ cd $ORACLE_HOME/bin

调用 nid 命令进行设置。

[oracle@MYTElife bin]$ nid target=sys/oracle

DBNEWID: Release 11.2.0.4.0 – Production on Wed Oct 19 19:29:34 2016

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

Connected to database TESTDB (DBID=2708979596)

Connected to server version 11.2.0

Control Files in database:

    /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl

    /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl

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

Proceeding with operation

Changing database ID from 2708979596 to 2708978718

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – modified

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – modified

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_system_bw773xok_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_sysaux_bw773xpr_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_undotbs1_bw773xqo_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_users_bw773xrv_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_MYTEdev_bw8xbqrz_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_inttestt_bw8xdnkt_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_epssite_by19vtnh_.db – dbid changed

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_temp_bw776mow_.tm – dbid changed

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – dbid changed

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – dbid changed

    Instance shut down

Database ID for database TESTDB changed to 2708978718.

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.

启动数据库,由于新的 DBID 出现,需要使用 resetlogs 命令启动。

[oracle@MYTElife bin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 19:30:08 2016

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            872417904 bytes

Database Buffers        2650800128 bytes

Redo Buffers              15405056 bytes

Database mounted.

SQL> alter database open resetlogs;

Database altered.

SQL> select dbid, name from v$database;

      DBID NAME

———- ———

2708978718 TESTDB

由于 DBNAME 没有修改,参数文件、密码文件和 Oracle Net 不需要进行修改。

4、修改 DBNAME 情况

如果单独修改 DBNAME,需要修改的文本类型文件多一些。但是,启动数据库时候不需要 resetlogs,并且归档日志、备份集合都可以使用。

操作同样,都是在 mount 状态上。

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            872417904 bytes

Database Buffers        2650800128 bytes

Redo Buffers              15405056 bytes

Database mounted.

调用 nid 命令。

[oracle@MYTElife bin]$ nid target=sys/oracle dbname=MYTEdb setname=yes

DBNEWID: Release 11.2.0.4.0 – Production on Wed Oct 19 19:46:11 2016

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

Connected to database TESTDB (DBID=2708978718)

Connected to server version 11.2.0

Control Files in database:

    /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl

    /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl

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

Proceeding with operation

Changing database name from TESTDB to MYTEDB

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – modified

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – modified

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_system_bw773xok_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_sysaux_bw773xpr_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_undotbs1_bw773xqo_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_users_bw773xrv_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_MYTEdev_bw8xbqrz_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_inttestt_bw8xdnkt_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_epssite_by19vtnh_.db – wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_temp_bw776mow_.tm – wrote new name

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – wrote new name

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – wrote new name

    Instance shut down

Database name changed to MYTEDB.

Modify parameter file and generate a new password file before restarting.

Succesfully changed database name.

DBNEWID – Completed succesfully.

设置 Oracle 环境变量到新的 ORACLE_SID 上。

[oracle@MYTElife dbs]$ su – oracle

Password: 

[oracle@MYTElife ~]$ cd $ORACLE_HOME/dbs

[oracle@MYTElife dbs]$ env | grep ORA

ORACLE_SID=MYTEdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

使用修改过 DBNAME 的 PFILE 启动数据库。

SQL> startup mount pfile=initMYTEdb.ora

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

SQL> alter database open;

Database altered.

之后,使用 create spfile from pfile 可以创建出新的 spfile。另外生成新的密码文件即可,具体操作详见上文。

5、结论

一般情况下,修改投产环境上 DBID 和 DBNAME 的场景不是很多。通过 nid 的系列测试,我们可以对这些关键信息分布在哪些文件中有一个比较清晰的认识和理解。记录下来,留待需要的朋友待查。

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-10/136568.htm

在 Oracle 中,DBID 和 DBNAME 是两个低调但又是及其重要的对象。作为标记信息,DBID 和 DBNAME 广泛的出现在参数文件、密码文件、数据文件和日志文件中,更有甚者在备份集合归档日志中。笔者看过一位前辈的文章中,强调称职 DBA 应该将管理数据库的 DBID 牢记于心。

一般情况下,已经创建好的数据库是不需要修改 DBID 和 DBNAME 信息的。因为,修改这些信息意味着 Oracle 关键信息的变化,和大量备份数据的废止。如果需要进行变更,一定要按照固定的操作程序,将对应的数据内容修改完好。

1、修改 DBID 和 DBNAME,是一个大事情

DBID 是一个十进制数字,Oracle 依据唯一性算法计算得到作为内部数据库的标记信息。在数据文件、日志和备份集合中,DBID 都是作为重要标记进行使用。DBNAME 是用户设置的项目内容,分布在密码文件、参数文件和数据文件中。如果存在修改 DBID 的情况,Online Redo Log 需要进行 ResetLog 操作,原有的归档和备份文件都需要废除失效。

对修改 DBID 和 DBNAME 操作,我们一定要明确后续调整和修复的范围动作。如果修改 DBID,所有之前进行的备份和归档日志就没有效用了。整个过程就和全新创建数据库(除了数据文件存在)没有差异。我们启动数据库 Open 的时候,就需要 resetlogs 模式启动,刷新废除所有的 online redo logs 组,开启一个新的 Sequence 序列。在投产条件下,如果我们修改了 DBID,就必须立即进行数据库备份动作,避免数据库裸奔。

如果修改了 DBNAME,问题简单一些,是不需要我们 resetlogs 的。之前的备份集合和归档日志还是可以继续使用。DBNAME 修改要求手工的在 SPFile 或者 Pfile 中修改初始化参数,密码文件也需要进行修改。注意:对应控制文件的备份,如果希望使用只前备份的控制文件恢复,就需要使用之前的参数文件进行启动。

#

文件信息

受影响参数

NID 是否处理

1

Password File

DBNAME

2

Parameter File

DBNAME

3

Data File

DBNAMEDBID

 

4

Online Redo Log

DBID

 

5

Archived Redo Log

DBID

6

Backup Set

DBID

7

Control File

DBIDDBNAME

 

8

Oracle NET File

DBNAME

9

DBConsole

DBIDDBNAME

下面,通过一系列的实验,演示如何使用 Oracle NID 工具进行 DBID 和 DBNAME 修改。

2、同时修改 DBID 和 DBNAME

当前笔者使用 11.2.0.4 数据库进行测试,数据库处在归档模式下。当前数据库名称为 MYTEDB,对应的 DBID 如下所示。

SQL> select * from v$version;

BANNER

——————————————————————————–

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

PL/SQL Release 11.2.0.4.0 – Production

CORE    11.2.0.4.0      Production

TNS for Linux: Version 11.2.0.4.0 – Production

NLSRTL Version 11.2.0.4.0 – Production

SQL> select dbid, name from v$database;

      DBID NAME

———- ———

2764682050 MYTEDB

SQL> archive log list;

Database log mode              Archive Mode

Automatic archival            Enabled

首先,确认备份和归档日志情况。查看环境变量信息。

[oracle@MYTElife ~]$ env | grep ORA

ORACLE_SID=MYTEdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

[oracle@MYTElife ~]$ cd $ORACLE_HOME/bin

[oracle@MYTElife bin]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1/bin

如果配置了 DBConsole,需要删除 DBConsole 对象。之后完全关闭,重新启动进行 mount 状态。同时,确认一下 Oracle Net 目录中三个文件:tnsnames.ora、listener.ora 和 sqlnet.ora,其中包括 DBNAME 项目,都需要修改。

[oracle@MYTElife bin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:45:58 2016

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

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

进入 $ORACLE_HOME/bin 文件夹,调用 nid 命令。

[oracle@MYTElife bin]$ nid target=sys/oracle dbname=testdb

DBNEWID: Release 11.2.0.4.0 – Production on Wed Oct 19 18:48:44 2016

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

Connected to database MYTEDB (DBID=2764682050)

Connected to server version 11.2.0

Control Files in database:

    /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl

    /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl

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

Proceeding with operation

Changing database ID from 2764682050 to 2708979596

Changing database name from MYTEDB to TESTDB

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – modified

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – modified

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_system_bw773xok_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_sysaux_bw773xpr_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_undotbs1_bw773xqo_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_users_bw773xrv_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_MYTEdev_bw8xbqrz_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_inttestt_bw8xdnkt_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_epssite_by19vtnh_.db – dbid changed, wrote new name

    Datafile /u01/app/oracle/oradata/MYTEDB/datafile/o1_mf_temp_bw776mow_.tm – dbid changed, wrote new name

    Control File /u01/app/oracle/oradata/MYTEDB/controlfile/o1_mf_bw7762ov_.ctl – dbid changed, wrote new name

    Control File /u01/app/oracle/fast_recovery_area/MYTEDB/controlfile/o1_mf_bw7762v3_.ctl – dbid changed, wrote new name

    Instance shut down

Database name changed to TESTDB.

Modify parameter file and generate a new password file before restarting.

Database ID for database TESTDB changed to 2708979596.

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.

在提示信息中,可以清晰看到 Oracle NID 名称将数据文件中的 DBID 和 Name 信息修改,并且在提示中提醒了需要修改内容。

在 alert log 中,我们看到了 DBID 和 Name 的变化过程。

Wed Oct 19 18:49:04 2016

*** DBNEWID utility started ***

DBID will be changed from 2764682050 to new DBID of 2708979596 for database MYTEDB

DBNAME will be changed from MYTEDB to new DBNAME of TESTDB

Starting datafile conversion

Datafile conversion complete

Database name changed to TESTDB.

Modify parameter file and generate a new password file before restarting.

Database ID for database TESTDB changed to 2708979596.

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open with RESETLOGS option.

Succesfully changed database name and ID.

*** DBNEWID utility finished succesfully ***

下面,需要修改 Spfile 中的 dbname 信息。方法和以前用到的相同,都是通过 spfile 生成 pfile,手工修改其中的 db_name 参数。

[oracle@MYTElife trace]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:51:26 2016

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> create pfile from spfile;

File created.

修改生成 initMYTEdb.ora 文件。

[oracle@MYTElife trace]$ cd $ORACLE_HOME/dbs

[oracle@MYTElife dbs]$ ls -l

total 9544

-rw-r—– 1 oracle oinstall    1544 Oct 19 18:49 hc_MYTEdb.dat

-rw-r–r– 1 oracle oinstall    2851 May 15  2009 init.ora

-rw-r–r– 1 oracle oinstall    1092 Oct 19 18:51 initMYTEdb.ora

-rw-r—– 1 oracle oinstall      24 Aug  7  2015 lkMYTEDB

[oracle@MYTElife dbs]$ vi initMYTEdb.ora 

MYTEdb.__large_pool_size=184549376

*.db_create_file_dest=’/u01/app/oracle/oradata’

*.db_domain=”

*.db_name=’testdb’

*.db_recovery_file_dest=’/u01/app/oracle/fast_recovery_area’

*.db_recovery_file_dest_size=10737418240

如果使用 ASM,还要修改 ASM 文件名。之后就可以使用新的 testdb 来启动。

[oracle@MYTElife dbs]$ export ORACLE_SID=testdb

[oracle@MYTElife dbs]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Wed Oct 19 18:54:26 2016

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

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup mount pfile=initMYTEdb.ora       

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

Open 数据库时候,由于是一个全新的 DBID,所以需要 resetlogs 模式。在日志上,我们的确也看到了 Oracle 删除原有 online redo log 动作的过程。

SQL> alter database open resetlogs;

Database altered.

–alert log 信息

Wed Oct 19 18:56:59 2016

alter database open resetlogs

RESETLOGS after complete recovery through change 1719246

Resetting resetlogs activation ID 2764689218 (0xa4c9cf42)

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_1_bw77672y_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_1_bw7767d4_.log

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_2_bw776938_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_2_bw7769cc_.log

Deleted Oracle managed file /u01/app/oracle/oradata/MYTEDB/onlinelog/o1_mf_3_bw776cck_.log

Deleted Oracle managed file /u01/app/oracle/fast_recovery_area/MYTEDB/onlinelog/o1_mf_3_bw776cmv_.log

Wed Oct 19 18:57:03 2016

Setting recovery target incarnation to 2

重新生成 spfile。

SQL> create spfile from memory;

File created.

创建密码文件,对应新的 testdb 的数据库名称。

[oracle@MYTElife dbs]$ ls -l | grep orapw

-rw-r—– 1 oracle oinstall    1536 Aug  7  2015 orapwMYTEdb

[oracle@MYTElife dbs]$ orapwd file=orapwtestdb password=oracle entries=10 force=y

[oracle@MYTElife dbs]$ ls -l | grep orapw

-rw-r—– 1 oracle oinstall    1536 Aug  7  2015 orapwMYTEdb

-rw-r—– 1 oracle oinstall    2560 Oct 19 19:02 orapwtestdb

查看监听器状态,修改 Oracle NET 文件。

[oracle@MYTElife dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 – Production on 19-OCT-2016 19:09:51

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

————————

Alias                    LISTENER

(篇幅原因,有省略……)

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Services Summary…

Service “testdb” has 1 instance(s).

  Instance “testdb”, status READY, has 1 handler(s) for this service…

Service “testdbXDB” has 1 instance(s).

  Instance “testdb”, status READY, has 1 handler(s) for this service…

The command completed successfully

对应新生成的 dbid 和 dbname 信息。

SQL> select dbid, name from v$database;

      DBID NAME

———- ———

2708979596 TESTDB

最后,如果使用了 global_name 参数,也要进行修改。

注意:如果是 Windows 环境的话,DBNAME 修改,在 Services 列表中需要重新生成服务。另外,修改 DBID 之后,原有的所有备份都失效了,需要重新备份。

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2016-10/136568p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计23738字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中