欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用DBNEWID Utility 修改oracle数据库的 db name 和 dbid

程序员文章站 2022-05-28 12:33:53
使用DBNEWID Utility 工具可以同时修改数据库名、DBID,也可以只修改其中一项 官方参考: https://docs.oracle.com/cd/E11882_01/server.112/e22490/dbnewid.htm#SUTIL014 一、同时修改db name 和 dbid ......

 

使用DBNEWID Utility 工具可以同时修改数据库名、DBID,也可以只修改其中一项

 

官方参考:

 

 

一、同时修改db name 和 dbid  (本例:emdb -> mydb)

1.修改之前建议给数据库做个全备。

 

2.干净关闭数据库,并重启到mount状态

shutdown immediate;

startup mount;

 

3.开始使用nid 工具修改数据库名和dbid

[oracle@Database ~]$ which nid
/u01/app/oracle/product/11.2.0.4/db_1/bin/nid

查看命令帮助:

[oracle@Database ~]$ nid -help

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jun 5 15:03:50 2018

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

 

[oracle@Database ~]$ nid target=sys dbname=mydb

DBNEWID: Release 11.2.0.4.0 - Production on Tue Jun 5 15:04:37 2018

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

Password:
Connected to database EMDB (DBID=2097101097)

Connected to server version 11.2.0

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

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

Proceeding with operation
Changing database ID from 2097101097 to 2892995079
Changing database name from EMDB to MYDB
Control File /u01/app/oracle/oradata/emdb/control01.ctl - modified
Control File /u01/app/oracle/oradata/emdb/control02.ctl - modified
Datafile /u01/app/oracle/oradata/emdb/system01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/sysaux01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/undotbs01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/users01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/mgmt_ecm_depot1.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/mgmt.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/mgmt_deepdive.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/emdb/temp01.db - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/emdb/control01.ctl - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/emdb/control02.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to MYDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database MYDB changed to 2892995079.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

 

4.最后修改参数文件中的db_name

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1853947904 bytes
Fixed Size 2254264 bytes
Variable Size 939526728 bytes
Database Buffers 905969664 bytes
Redo Buffers 6197248 bytes
SQL> alter system set db_name='mydb' scope=spfile;

System altered.

SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.

 

5. 以resetlogs方式打开数据库

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1853947904 bytes
Fixed Size 2254264 bytes
Variable Size 939526728 bytes
Database Buffers 905969664 bytes
Redo Buffers 6197248 bytes
Database mounted.

SQL> alter database open resetlogs;

 

二、只修改dbid (在使用nid 命令不加dbname参数即可)

 

[oracle@Database ~]$ nid target=sys dbname=mydb

 

三、只修改dbname  (在nid 命令中 加上 SETNAME=YES 选项,表示只修改数据库名称)

 

[oracle@Database ~]$ nid target=sys dbname=mydb SETNAME=YES