这篇文章主要介绍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”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。