oracle 更改 db_name 的方法

本文介绍如何使用Oracle DBNEWID工具更改数据库名称,并演示了整个过程,包括参数文件的创建、控制文件的修改以及实例的重启。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

运行下面的命令,即可更改db_name 从haha 更改为test

>nid target=sys/gaokai@haha dbname=test

下面演示:

C:\Documents and Settings\andyleng>set ORACLE_SID=haha

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:07:00 2011

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             234882472 bytes
Database Buffers          536870912 bytes
Redo Buffers                5259264 bytes
Database mounted.
Database opened.
SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      haha
db_unique_name                       string      haha
global_names                         boolean     FALSE
instance_name                        string      haha
lock_name_space                      string
log_file_name_convert                string
service_names                        string      haha
SQL> create pfile from spfile;

File created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

C:\Documents and Settings\andyleng>

 

C:\Documents and Settings\andyleng>set ORACLE_SID=haha

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:08:40 2011

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             234882472 bytes
Database Buffers          536870912 bytes
Redo Buffers                5259264 bytes
Database mounted.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr
oduction
With the Partitioning, OLAP, Data Mining and Real Application Testing options

C:\Documents and Settings\andyleng>nid target=sys/oracle@haha dbname=test

DBNEWID: Release 11.2.0.1.0 - Production on Wed Nov 2 18:11:10 2011

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

Connected to database HAHA (DBID=3533083211)

Connected to server version 11.2.0

Control Files in database:
    D:\ORACLE\ORADATA\TEST\CONTROL01.CTL
    D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL

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

Proceeding with operation
Changing database ID from 3533083211 to 2064306111
Changing database name from HAHA to TEST
    Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - modified
    Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - modified
    Datafile D:\ORACLE\ORADATA\TEST\SYSTEM01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\SYSAUX01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\UNDOTBS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\USERS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\ATG_TBS01.DB - dbid changed, wrote new name
    Datafile D:\ORACLE\ORADATA\TEST\ATG_LOBTBS01.DB - dbid changed, wrote new na
me
    Datafile D:\ORACLE\ORADATA\TEST\TEMP01.DB - dbid changed, wrote new name
    Control File D:\ORACLE\ORADATA\TEST\CONTROL01.CTL - dbid changed, wrote new
name
    Control File D:\ORACLE\FLASH_RECOVERY_AREA\TEST\CONTROL02.CTL - dbid changed
, wrote new name
    Instance shut down

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


C:\Documents and Settings\andyleng>ORADIM -del -sid haha
Instance deleted.

C:\Documents and Settings\andyleng>oradim -new -sid test
Instance created.

C:\Documents and Settings\andyleng>set ORACLE_SID=test

C:\Documents and Settings\andyleng>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 2 18:12:50 2011

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

SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  778387456 bytes
Fixed Size                  1374808 bytes
Variable Size             427820456 bytes
Database Buffers          343932928 bytes
Redo Buffers                5259264 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SQL> create spfile from pfile;

File created.

SQL> alter database open resetlogs;

Database altered.

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      test
db_unique_name                       string      test
global_names                         boolean     FALSE
instance_name                        string      test
lock_name_space                      string
log_file_name_convert                string
service_names                        string      test
SQL>


 

<think>好的,用户的问题是在Oracle RAC环境中如何修改DB_NAME。我需要根据提供的引用内容来整理步骤。首先,引用3提到了在RAC集群中修改DB_NAME的过程,但步骤可能不够详细。引用1和引用2讨论了修改DB_UNIQUE_NAME时遇到的问题,特别是节点启动问题。需要确保在修改DB_NAME时,所有节点都能正常启动。 用户可能需要的步骤包括:检查当前参数、关闭数据库、修改参数文件、使用nid工具、更新集群配置等。同时需要注意参数如db_files的修改方法(引用4),但这里主要是DB_NAME。需要结合RAC环境,确保所有节点同步,并处理可能出现的错误,如实例无法启动的情况。还要提醒备份和测试环境的重要性,避免生产环境风险。</think>### Oracle RAC环境修改DB_NAME操作指南 在Oracle RAC环境中修改数据库名称($DB_NAME$)需谨慎操作,以下是详细步骤: #### 1. **预检查与准备** - 备份数据库(RMAN全库备份+控制文件备份) - 检查当前$DB_NAME$和$DB_UNIQUE_NAME$: ```sql SQL> show parameter name; ``` 确认输出包含以下关键参数: ```plaintext NAME TYPE VALUE ------------------------------------ ----------- -------------------------- db_name string old_dbname db_unique_name string old_dbname_adg ``` - 确保所有RAC节点处于正常运行状态 #### 2. **关闭数据库** ```sql SQL> shutdown immediate; ``` **注意**:需在所有实例执行关闭操作[^3] #### 3. **修改参数文件** - 修改$ORACLE_HOME/dbs/init.ora或SPFILE中的参数: ```sql *.db_name='new_dbname' ``` - **RAC特有步骤**:更新集群注册信息: ```sql srvctl modify database -db old_dbname -newdb new_dbname ``` #### 4. **使用DBNEWID工具** ```bash nid target=/ dbname=new_dbname ``` **关键响应选项**: ```plaintext Do you want to proceed? (Y/[N]) => Y ``` #### 5. **更新集群配置** - 删除原数据库资源: ```bash srvctl remove database -db old_dbname ``` - 创建新数据库资源: ```bash srvctl add database -db new_dbname -o $ORACLE_HOME srvctl add instance -db new_dbname -instance new_dbname1 -node racnode1 srvctl add instance -db new_dbname -instance new_dbname2 -node racnode2 ``` #### 6. **启动数据库验证** ```sql SQL> startup mount; SQL> alter database open; ``` 验证所有节点状态: ```bash srvctl status database -db new_dbname ``` #### 7. **后置处理** - 更新监听器配置(listener.ora) - 修改tnsnames.ora中的服务名 - 检查ASM磁盘组中的控制文件路径 ### 常见问题处理 1. **节点启动失败**:检查$ORACLE_SID$是否同步更新,确认ocrregister信息一致性[^2] 2. **控制文件报错**:使用备份的控制文件恢复 3. **服务注册异常**:执行`alter system register`强制注册 **注意**:生产环境建议先在测试环境验证操作流程,操作窗口需预留回退时间[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值