DB_NAME DB_UNIQUE_NAME 和 SID 的理解

本文详细介绍了在Oracle数据库中如何更改DB_NAME和DBID,包括使用NID工具的不同场景及步骤,以及这些更改对数据库的影响。

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

1. DB_NAME 表示数据库名称,DB_NAME 会保持在数据文件头、控制文件、REDO文件里,所以更改DB_NAME不能仅仅修改spfile ,还需要用nid 来进行更改,并且更改后还需要手工做些工作,使其生效。
DB_NAME 最长 8 个字符。

2. 在 DG下,主库和物理从库的 DB_NAME 是一致的,主库和物理从库的DB_UNIQUE_NAME 不同,DB_UNIQUE_NAME 用于标识主从库。

修改 DB_UNIQUE_NAME 需要修改 spfile 并重启数据库;
由于 DB_NAME 记录在数据文件头、控制文件、REDO文件里,所以修改 DB_NAME 一般有两种方式:
(1)备份控制文件到trace,修改 spfile,重启数据库,resetlogs 打开数据库
(2)或者通过 nid 命令修改

3. SID:System Identifier

The SID identifies the instance's shared memory on a host, but may not uniquely distinguish this instance
from other instances

doc上把sid解释为在host上用sid来标示实例的共享内存的,可见sid主要是和os打交道的。

sid可以通过如下语句在库中查询: select instance_name from v$instance;

(I):如果你只想更改数据库的id(dbid),那么你只需要指定target参数就可以了,具体的操作过程,请参考如下:

1. Backup the database
2. SHUTDOWN IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db
5. Shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter
file to the new database name
7. Create a new password file
8. Startup of the database with open resetlogs

(II):如果你想只更改数据库名(db_name),那么你需要设置SETNAME参数为Y,同时指定DBNAME参数,具体的操作过程,请参考如下:

1. Backup the database
2. SHUTDOWN IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db DBNAME=test_db2 SETNAME=Y
- the value of DBNAME is the new dbname of the database
- SETNAME must be set to Y. The default is N and causes the
DBID to be changed also.
5. shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter
file to the new database name
7. Create a new password file
8. Startup of the database(without resetlogs)

(III):如果你想同时更改数据库名(db_name)和数据库ID(dbid),那么你要指定DBNAME参数,同时设置SETNAME为N(其值默认也为N),具体操作过程,请参考如下:

1. Backup of the database.
2. Shutdown IMMEDIATE of the database
3. STARTUP MOUNT
4. Open one session and run NID with sysdba privileges
% nid TARGET=SYS/password@test_db DBNAME=test_db2
- the value of DBNAME is the new dbname of the database
5. After DBNEWID successfully changes the DBID,Shutdown IMMEDIATE of the database
6. Set the DB_NAME initialization parameter in the initialization parameter file to the new database name.
7. Create a new password file.
8. Startup of the database with open resetlogs

(IV):如果你只更改了数据库名,而没有更改数据库id,那么你打开数据库就不需要open resetlogs了。

在构建DG的时候,从库上提示:

ORA-16047: DGID mismatch between destination setting and standby


其实就是主从库上配置的 db_unique_name, log_archive_config 参数是否匹配导致的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值