绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
和修改Oracle数据库的db_name
2021-08-20 16:00:56

如何修改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没有变化

测试完毕!








分享好友

分享这个小栈给你的朋友们,一起进步吧。

Oracle运维新鲜事-技术与管理各占半边天
创建时间:2020-08-04 11:34:57
本技术栈旨在分享技术心得,运维趣事,故障处理经验,调优案例,故障处理涉及集群,DG,OGG,大家生产中遇到的问题基本都会囊括了,我会发布生产库遇到的故障,希望在交流中互助互益,共同提高,也希望大家讨论,如果您有生产中遇到的集群问题,也可以在这里提出来,一起讨论,现实中也帮助不少同学解决了生产库的故障。
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

栈主、嘉宾

查看更多
  • Abraham林老师
    栈主
  • 小雨滴
    嘉宾
  • hawkliu
    嘉宾
  • u_97a59a25246404
    嘉宾

小栈成员

查看更多
  • 栈栈
  • dapan
  • 小菜鸟___
  • hwayw
戳我,来吐槽~