oracle12C如何更改dbname?
oracle 12.2.0.1 版本:先生成控制文件trace:
alter database backup controlfile to trace;
oradebug setmypid;
oradebug tracefile_name;
根据trace文件获得得创建控制文件的脚本。
先建立一个initATPuat.ora文件:
create pfile='/ATPapp/oraATP/home/initATPuat.ora' from spfile;
修改initATPuat.ora中的ATP改成ATPuat,同时将os oracle用户下的.bash_profile中的ORACLE_SID改成ATPuat.
并以pfile启动到nomount状态
进入到asmcmd下,将原control文件删除。
SQL> show parameter db_create
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string +ATPDG1
db_create_online_log_dest_1 string
db_create_online_log_dest_2 string
db_create_online_log_dest_3 string
db_create_online_log_dest_4 string
db_create_online_log_dest_5 string
只有db_create_file_dest有值,那么ORACLE会在db_create_file_dest目录创建两份控制文件
重新整理更改db name后的控制文件如下:
CREATE CONTROLFILE set DATABASE "ATPUAT" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 (
'+ATPDG1/ATP/ONLINELOG/group_1.259.965469981',
'+ATPDG1/ATP/ONLINELOG/group_1.260.965469981'
) SIZE 200M BLOCKSIZE 512,
GROUP 2 (
'+ATPDG1/ATP/ONLINELOG/group_2.261.965469983',
'+ATPDG1/ATP/ONLINELOG/group_2.262.965469983'
) SIZE 200M BLOCKSIZE 512,
GROUP 3 (
'+ATPDG1/ATP/ONLINELOG/group_3.263.965469985',
'+ATPDG1/ATP/ONLINELOG/group_3.264.965469985'
) SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'+ATPDG1/ATP/DATAFILE/system.265.965469987',
'+ATPDG1/ATP/62C80FC16441609AE053B05A100A2C8B/DATAFILE/system.266.965469991',
'+ATPDG1/ATP/DATAFILE/sysaux.267.965469997',
'+ATPDG1/ATP/62C80FC16441609AE053B05A100A2C8B/DATAFILE/sysaux.268.965469999',
'+ATPDG1/ATP/DATAFILE/undotbs1.269.965470001',
'+ATPDG1/ATP/62C80FC16441609AE053B05A100A2C8B/DATAFILE/undotbs1.270.965470001',
'+ATPDG1/ATP/DATAFILE/users.273.965470023',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/system.275.965475081',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/sysaux.277.965475081',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/undotbs1.276.965475081',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/users.279.965475137',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/dbo_webiplined.280.965554337',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/dbo_webiplinex.281.965554411',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/gpatd.282.965555729',
'+ATPDG1/ATP/62C93F2857BF4ECDE053B05A100ABBE6/DATAFILE/gpatx.283.965555849'
CHARACTER SET AL32UTF8;;
报错如下:
CREATE CONTROLFILE set DATABASE "ATPUAT" RESETLOGS NOARCHIVELOG
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-00200: control file could not be created
ORA-00202: control file: '+ATPDG1/ATP/CONTROLFILE/current.257.965469981'
ORA-17502: ksfdcre:4 Failed to create file
+ATPDG1/ATP/CONTROLFILE/current.257.965469981
ORA-15046: ASM file name '+ATPDG1/ATP/CONTROLFILE/current.257.965469981' is
not in single-file creation form
关闭DB,并将initATPuat.ora文件中下面行标识掉:
#*.control_files='+ATPDG1/ATP/CONTROLFILE/current.257.965469981','+ATPDG1/ATP/CONTROLFILE/current.258.965469981'
启动db到nomount状态,并重新建立控制文件成功;
将spfile建回ASM磁盘组:
create spfile='+ATPdg1' from memory;
将$ORACLE_HOME/dbs下的原spfile文件改名,建立并修改initmdpuat.ora内容指向ASM磁盘的spfile:
cd $ORACLE_HOME/dbs
vi initATPuat.ora
spfile='+ATPdg1/ATPuat/PARAMETERFILE/spfile.284.965569549'
执行:alter database open resetlogs
select name,open_mode from v$pdbs;
确认cdb为read only状态,而pdb为mount状态,再打开pdp:
alter session set container=ATPuap;
startup
为了让下一次pdb跟随cdb一次性启动,需要在cdb下执行:
alter pluggable database pdb名 save state
最后注册如下信息:
更改OCR中的db_unique_name为ATPuat,操作如下:
1.停库和从ocr中移除库
srvctl remove database -d ATP
2 cluster级别添加database资源
srvctl add database -d ATPuat -n ATPuat -o /ATPapp/orapat/12.2.0
3 修改ocr中db与asm磁盘组的依赖关系
srvctl modify database -d ATPuat -a "ATPDG1"
4重新注册service(需要的话)
su - oracpl
srvctl add service -d nhcpl -s bmpl -r bpmpl1 -a bpmpl2 -P basic -e select -m basic
srvctl add service -d nhcpl -s bdmr -r bpmpl2 -a bpmpl1 -P basic -e select -m basic
启动 service
srvctl start service -d nhcpl -s bmpl
srvctl start service -d nhcpl -s bdmr