DB_NAME DB_UNIQUE_NAME 和 SID 的理解

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 参数是否匹配导致的。

posted @ 2017-11-11 10:28  ClarkYu  阅读(2600)  评论(0编辑  收藏  举报