共计 2506 个字符,预计需要花费 7 分钟才能阅读完成。
这篇文章主要介绍 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”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注丸趣 TV 行业资讯频道!