oracle nid修改dbname
db_name由ora19c修改成test22,小记一下
1、检查当前db_name
sys@ORA19C>show parameter name
NAME TYPE VALUE
--------------------------- --------------- ------------
cdb_cluster_name string
cell_offloadgroup_name string
db_file_name_convert string
db_name string ora19c
db_unique_name string ora19c
global_names boolean FALSE
instance_name string ora19c
lock_name_space string
log_file_name_convert string
pdb_file_name_convert string
processor_group_name string
service_names string ora19c
2、修改sys密码,知道了忽略此步
sys@ORA19C>alter user sys identified by qwer1234;
3、查看并创建参数文件,如果使用spfile启动则创建pfile,方便后期修改启动
sys@ORA19C>show parameter pfile
NAME TYPE VALUE
----------- ------------- ---------
spfile string /u01/app/oracle/product/19.3.0
/db_1/dbs/spfileora19c.ora
sys@ORA19C>create pfile='/home/oracle/pfile_1208.ora' from spfile;
4、关闭并mount数据库
sys@ORA19C>shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORA19C>startup mount
ORACLE instance started.
Total System Global Area 1593831928 bytes
Fixed Size 8897016 bytes
Variable Size 1191182336 bytes
Database Buffers 385875968 bytes
Redo Buffers 7876608 bytes
Database mounted.
sys@ORA19C>exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.13.0.0.0
5、修改db_name
[oracle@rhel76 ~]\$ nid target=sys/qwer1234 dbname=test22
DBNEWID: Release 19.0.0.0.0 - Production on Thu Dec 8 16:18:38 2021
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Connected to database ORA19C (DBID=1162054459)
Connected to server version 19.13.0
Control Files in database:
/u01/app/oracle/oradata/ORA19C/control01.ctl
/u01/app/oracle/oradata/ORA19C/control02.ctl
--回复Y
Change database ID and database name ORA19C to TEST22? (Y/[N]) => Y
Proceeding with operation
Changing database ID from 1162054459 to 216219870
Changing database name from ORA19C to TEST22
Control File /u01/app/oracle/oradata/ORA19C/control01.ctl - modified
Control File /u01/app/oracle/oradata/ORA19C/control02.ctl - modified
Datafile /u01/app/oracle/oradata/ORA19C/system01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/spa.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/sysaux01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/undotbs01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/ogg01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/users01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/DATA_TEST01.db - dbid changed, wrote new name
Datafile /u01/app/oracle/oradata/ORA19C/temp01.db - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/ORA19C/control01.ctl - dbid changed, wrote new name
Control File /u01/app/oracle/oradata/ORA19C/control02.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to TEST22.
Modify parameter file and generate a new password file before restarting.
Database ID for database TEST22 changed to 216219870.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
[oracle@rhel76 ~]\$
6、修改环境变量和参数文件
vi .bash_profile
export ORACLE_SID=test22
#export ORACLE_UNQNAME=test222
[oracle@rhel76 ~]\$ vi pfile_1208.ora
#*.db_name='ora19c'
*.db_name='test22'
7、启动数据库
idle>startup pfile='/home/oracle/pfile_1208.ora';
ORACLE instance started.
Total System Global Area 1593831928 bytes
Fixed Size 8897016 bytes
Variable Size 922746880 bytes
Database Buffers 654311424 bytes
Redo Buffers 7876608 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
idle>alter database open resetlogs;
8、修改之后alter日志文件变化了
--原来
[oracle@rhel76 trace]\$ pwd
/u01/app/oracle/diag/rdbms/ora19c/ora19c/trace
--新的
[oracle@rhel76 trace]\$ cd /u01/app/oracle/diag/rdbms/test22/test22/
[oracle@rhel76 trace]\$ tailf alert_test22.log
9、重新设置spfile启动,重启生效
create spfile from pfile='/home/oracle/pfile_1208.ora';
[oracle@rhel76 dbs]\$ pwd
/u01/app/oracle/product/19.3.0/db_1/dbs
[oracle@rhel76 dbs]\$ ls -ltrh *.ora
-rw-r--r-- 1 oracle oinstall 3.1K May 14 2015 init.ora
-rw-r----- 1 oracle oinstall 3.5K Dec 8 16:17 spfileora19c.ora
-rw-r----- 1 oracle oinstall 3.5K Dec 8 16:40 spfiletest22.ora
10、修改tnsname,别名和SERVICE_NAME 改为test22
[oracle@rhel76 admin]\$ vi listener.ora
test22 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.22)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test22)
)
)
11、重新加载或重启监听
[oracle@rhel76 admin]\$ lsnrctl status