ORACLE中在不删库的情况下如何直接修改数据库dbname
这篇文章主要介绍ORACLE中在不删库的情况下如何直接修改数据库dbname,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
环境: Red 6.4 ORACLE:11.2.0.4
原库dbname:mai
新库dname:prod
为验证更改dbname之后数据是否会修改需做以下操作:
原库:mai
SQL>alter user hr identified by oracle123 account unlock;
SQL> conn hr/oracle
SQL>create table abc (id int,name varchar(20));
SQL>insert into abc (1 'ok',2 'sdad');
SQL> commit;
Commit complete.
SQL> create pfile='initprod.ora' from spfile;
SQL> !nid target=sys/oracle123 dbname=prod logfile=/tmp/change.log
SQL> shu immediate;
ORA-03135: connection lost contact
这个时候需要退出sqlplus 重新指定ORACLE_SID
[oracle@node1 ~]$ export ORACLE_SID=prod
[oracle@node1 ~]$ sqlplus / as sysdba
将数据库启动到mount
SQL> startup mount;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 1157628808 bytes
Database Buffers 3103784960 bytes
Redo Buffers 12107776 bytes
ORA-01103: database name 'PROD' in control file is not 'MAI'
SQL> alter system set db_name=prod scope=spfile; ##因为没有使用spfile导致报错
alter system set db_name=prod scope=spfile
*
ERROR at line 1:
ORA-32001: write to SPFILE requested but no SPFILE is in use
创建spfile
SQL> create spfile from pfile;
File created.
关库使其使用spfile
SQL> shu immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 1157628808 bytes
Database Buffers 3103784960 bytes
Redo Buffers 12107776 bytes
ORA-01103: database name 'PROD' in control file is not 'MAI'
修改dbname
SQL> alter system set db_name=prod scope=spfile;
System altered.
重启数据库
SQL> shu immediate;
ORA-01507: database not mounted
新库:prod
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
打开数据库
SQL> alter database open resetlogs;
Database altered.
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string PROD
db_unique_name string PROD
global_names boolean FALSE
instance_name string prod
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string PROD
验证数据是否丢失
SQL> select USERNAME,ACCOUNT_STATUS from dba_users;
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
SYS OPEN
SYSTEM OPEN
HR OPEN
OUTLN EXPIRED & LOCKED
连接hr用户
SQL> conn hr/oracle
SQL> select * from abc;
ID NAME
---------- --------------------
1 ok
2 sdad
以上是“ORACLE中在不删库的情况下如何直接修改数据库dbname”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341