DBNEWID 是一个数据库实用程序,用于更改 Oracle 数据库的 DBNAME 和 DBID。可以更改 DBID 或 DBNAME 或两者。
DBNAME 是在创建数据库时指定的数据库名称,DBID 是创建数据库时分配给数据库的唯一编号。
以下步骤演示如何使用 DBNEWID 实用程序更改 Oracle 数据库的 DBNAME 和 DBID。
重要提示:开始此过程之前,请确保拥有数据库的完整备份。
Step 1:开始之前,找出数据库当前的 DBNAME 和 DBID:
bash
SQL> SELECT DBID,NAME from V$DATABASE;
DBID NAME
---------- ---------
2426088413 MYORDB
Step 2:第一步是启动实例并挂载数据库,但不打开数据库。
bash
sqlplus / as sysdba
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1071333376 bytes
Fixed Size 1375792 bytes
Variable Size 553648592 bytes
Database Buffers 511705088 bytes
Redo Buffers 4603904 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 11g Release 11.2.0.1.0 - Production
Step 3. 通过指定连接字符串和数据库的新名称来运行 DBNEWID 实用程序。 连接字符串中指定的用户应具有 SYSDBA 权限。
bash
nid target=sys/MYPASS@MYORDB dbname=MYNEWDB setname=YES
DBNEWID: Release 11.2.0.1.0 - Production on Tue May 30 12:50:01 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to database MYORDB (DBID=2436089413)
Connected to server version 11.2.0
Control Files in database:
C:ORADATAMYORDBCONTROL01.CTL
C:ORADATAMYORDBCONTROL02.CTL
Change database name of database MYORDB to MYNEWDB? (Y/[N]) => Y
Proceeding with operation
Changing database name from MYORDB to MYNEWDB
Control File C:ORADATAMYORDBCONTROL01.CTL - modified
Datafile C:ORADATAMYORDBSYSTEM01.DB - wrote new name
Datafile C:ORADATAMYORDBSYSAUX01.DB - wrote new name
Datafile C:ORADATAMYORDBUNDOTBS01.DB - wrote new name
Datafile C:ORADATAMYORDBUSERS01.DB - wrote new name
Datafile C:ORADATAMYORDBMYORDBDAT01.DB - wrote new name
Datafile C:ORADATAMYORDBMYORDBIDX01.DB - wrote new name
Datafile C:ORADATAMYORDBTEMP01.DB - wrote new name
Control File C:ORADATAMYORDBCONTROL01.CTL - wrote new name
Control File C:ORADATAMYORDBCONTROL02.CTL - wrote new name
Instance shut down
Database name changed to MYNEWDB.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.
Step 4: Shut down the database.
bash
SQL> shutdown immediate
Step 5:将初始化参数文件中的DB_NAME初始化参数设置为新的数据库名称。
bash
sqlplus / as sysdba
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string MYORDB
SQL> alter system set db_name=MYNEWDB scope=spfile;
System altered.
Step 6: 创建一个新的密码文件。
bash
orapwd file=orapwMYNEWDB password=MYPASS
Step 7: 启动DB
bash
SQL> startup mount
Step 8:验证名称更改
bash
SELECT DBID,NAME from V$DATABASE;
DBID NAME
---------- ---------
2426088413 MYNEWDB