和修改Oracle数据库的db_name

2021-08-20 00:00:00 修改 数据库 专区 文件 生产

如何修改dbname
1 安全关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
2 启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.

Total System Global Area 3070227080 bytes
Fixed Size 8901256 bytes
Variable Size 738197504 bytes
Database Buffers 2315255808 bytes
Redo Buffers 7872512 bytes
Database mounted.

SQL> select dbid,name from v$database;

DBID NAME
---------- ------------------
492834486 PROD


3 nid修改
[oracle@rac1 PROD]$ nid target=sys/oracle@prod dbname=orcl setname=y

DBNEWID: Release 19.0.0.0.0 - Production on Fri Aug 20 15:45:05 2021

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

Connected to database PROD (DBID=492834486)

Connected to server version 19.3.0

Control Files in database:
/oracle/base/oradata/PROD/control01.ctl
/oracle/base/oradata/PROD/control02.ctl

Change database name of database PROD to ORCL? (Y/[N]) => y

Proceeding with operation
Changing database name from PROD to ORCL
Control File /oracle/base/oradata/PROD/control01.ctl - modified
Control File /oracle/base/oradata/PROD/control02.ctl - modified
Datafile /oracle/base/oradata/PROD/system01.db - wrote new name
Datafile /oracle/base/oradata/PROD/tbs_u1.db - wrote new name
Datafile /oracle/base/oradata/PROD/sysaux01.db - wrote new name
Datafile /oracle/base/oradata/PROD/undotbs01.db - wrote new name
Datafile /oracle/base/19.3/dbs/cachetblsp.db - wrote new name
Datafile /oracle/base/oradata/PROD/users01.db - wrote new name
Datafile /oracle/base/oradata/PROD/tbs_lob.db - wrote new name
Datafile /oracle/base/oradata/PROD/creccoa.db - wrote new name
Datafile /oracle/base/oradata/PROD/temp01.db - wrote new name
Control File /oracle/base/oradata/PROD/control01.ctl - wrote new name
Control File /oracle/base/oradata/PROD/control02.ctl - wrote new name
Instance shut down

Database name changed to ORCL.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.

提示:再打开数据库之前修改参数文件,并创建新得密码文件。
此时数据库已经关闭
4 关闭数据库,该步骤无需执行,上面操作自动关库了。
5 修改参数文件
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 3070227080 bytes
Fixed Size 8901256 bytes
Variable Size 738197504 bytes
Database Buffers 2315255808 bytes
Redo Buffers 7872512 bytes

SQL> show parameter db_name;

NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_name string prod

SQL> alter system set db_name=orcl scope=spfile;

System altered.

5 验证是否修改成功。
SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area 3070227080 bytes
Fixed Size 8901256 bytes
Variable Size 738197504 bytes
Database Buffers 2315255808 bytes
Redo Buffers 7872512 bytes
SQL> show parameter db_name;

NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_name string ORCL

6 重新创建密码文件。
[oracle@rac1 dbs]$ ls -lrt ora*
-rw-r----- 1 oracle dba 2048 Aug 19 14:51 orapwprod
[oracle@rac1 dbs]$ mv orapwprod orapworcl
[oracle@rac1 dbs]$ ls -lrt ora*
-rw-r----- 1 oracle dba 2048 Aug 19 14:51 orapworcl

7 重启数据库
SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL>
SQL>
SQL> startup
ORACLE instance started.

Total System Global Area 3070227080 bytes
Fixed Size 8901256 bytes
Variable Size 738197504 bytes
Database Buffers 2315255808 bytes
Redo Buffers 7872512 bytes
Database mounted.
Database opened.
SQL> show parameter db_name;

NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
db_name string ORCL
SQL> select dbid,name from v$database;

DBID NAME
---------- ------------------
492834486 ORCL

注意:此时不需要resetlogs.此时的dbid没有变化

测试完毕!








相关文章