自学内容网 自学内容网

Oracle 19c 修改db_name

将db_name=dcpfarei  修改成 db_name=dcpfardb,使用oracle自带的nid工具修改

修改前:
SQL> show parameter name
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cdb_cluster_name                     string
cell_offloadgroup_name               string
db_file_name_convert                 string
db_name                              string      dcpfarei
db_unique_name                       string      dcpfarei
global_names                         boolean     FALSE
instance_name                        string      dcpfardb
lock_name_space                      string
log_file_name_convert                string
pdb_file_name_convert                string
processor_group_name                 string
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      dcpfarei
1、切换到需要修改的实例环境下
[oracle@database-001 ~]$ export ORACLE_SID=dcpfardb
2、关闭数据库并且启动到mount状态
[oracle@database-001 ~]$ sqlplus / as sysdba
-- 关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

-- 启动到mount状态
SQL> startup mount;
ORACLE instance started.
                                                                                                                  
Total System Global Area 3.2212E+10 bytes
Fixed Size                 13634144 bytes
Variable Size            7717519360 bytes
Database Buffers         2.4428E+10 bytes
Redo Buffers               53473280 bytes
Database mounted.
SQL> 
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.17.0.0.0
[oracle@database-001 ~]$
3、修改db_name
[oracle@database-001 ~]$ nid target=sys dbname=dcpfardb  
                                                                                                                  
DBNEWID: Release 19.0.0.0.0 - Production on Mon Jul 22 09:21:35 2024
                                                                                                                  
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
                                                                                                                  
Password: 
Connected to database DCPFAREI (DBID=71171141)
                                                                                                                  
Connected to server version 19.17.0
                                                                                                                  
Control Files in database:
    /oracle/app/oracle/oradata/DCPFARDB/control01.ctl
    /oracle/app/oracle/fast_recovery_area/DCPFARDB/control02.ctl
                                                                                                                  
Change database ID and database name DCPFAREI to DCPFARDB? (Y/[N]) => y
                                                                                                                  
Proceeding with operation
Changing database ID from 71171141 to 333839022
Changing database name from DCPFAREI to DCPFARDB
    Control File /oracle/app/oracle/oradata/DCPFARDB/control01.ctl - modified
    Control File /oracle/app/oracle/fast_recovery_area/DCPFARDB/control02.ctl - modified
    Datafile /oracle/app/oracle/oradata/DCPFARDB/system.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/sysaux.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/undotbs.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_data.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_index.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_lob.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_skdata_purge_data.db - dbid changed, wrote new name
Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_skdata_purge_index.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_skdata_purge_lob.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares_index01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares_data01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/users01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/undotbs01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares_lob01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_index01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_data01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/dlex_tdp_fares1_lob01.db - dbid changed, wrote new name
    Datafile /oracle/app/oracle/oradata/DCPFARDB/temp01.db - dbid changed, wrote new name
    Control File /oracle/app/oracle/oradata/DCPFARDB/control01.ctl - dbid changed, wrote new name
    Control File /oracle/app/oracle/fast_recovery_area/DCPFARDB/control02.ctl - dbid changed, wrote new name
    Instance shut down
                                                                                                                  
Database name changed to DCPFARDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database DCPFARDB changed to 333839022.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
                                                                                                                  
[oracle@pet-datalex-ecs-database-001 ~]$ 
4、修改数据库动态启动文件参数
[oracle@pet-datalex-ecs-database-001 ~]$ ps -ef |grep smon
oracle    9384  8238  0 09:23 pts/0    00:00:00 grep --color=auto smon
oracle   18857     1  0 Jul21 ?        00:00:00 ora_smon_tstttdp1

[oracle@database-001 ~]$ export ORACLE_SID=dcpfardb
[oracle@database-001 ~]$ sqlplus / as sysdba
                                                                                                                  
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jul 22 09:23:18 2024
Version 19.17.0.0.0
                                                                                                                  
Copyright (c) 1982, 2022, Oracle.  All rights reserved.
                                                                                                                  
Connected to an idle instance.
                                                                                                                  
SQL> startup nomount;
ORACLE instance started.
                                                                                                                  
Total System Global Area 3.2212E+10 bytes
Fixed Size                 13634144 bytes
Variable Size            3690987520 bytes
Database Buffers         2.8454E+10 bytes
Redo Buffers               53473280 bytes

-- 修改数据库动态文件
SQL> alter system set db_name='dcpfardb' scope=spfile;
                                                                                                                  
System altered.
SQL> alter system set db_unique_name='dcpfardb' scope=spfile;
                                                                                                                  
System altered.
                                                                                                                  
SQL>
5、修改完动态文件,关闭数据库,重启数据库
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.17.0.0.0

[oracle@database-001 ~]$ export ORACLE_SID=dcpfardb
[oracle@database-001 ~]$ sqlplus / as sysdba
                                                                                                                  
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jul 22 09:28:27 2024
Version 19.17.0.0.0
                                                                                                                  
Copyright (c) 1982, 2022, Oracle.  All rights reserved.
                                                                                                                  
Connected to an idle instance.
                                                                                                                  
SQL> startup nomount;
ORACLE instance started.
                                                                                                                  
Total System Global Area 3.2212E+10 bytes
Fixed Size                 13634144 bytes
Variable Size            3690987520 bytes
Database Buffers         2.8454E+10 bytes
Redo Buffers               53473280 bytes
SQL> show parameter name
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cdb_cluster_name                     string
cell_offloadgroup_name               string
db_file_name_convert                 string
db_name                              string      dcpfardb
db_unique_name                       string      dcpfardb
global_names                         boolean     FALSE
lock_name_space                      string
log_file_name_convert                string
pdb_file_name_convert                string
processor_group_name                 string
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      dcpfardb
SQL> 
                                                                                                                  
Database altered.
                                                                                                                                                                  -- 通过上面查看,修改成功   
-- 打开数据库需要resetlogs方式打开                                                            
                                                                                                                  
SQL> alter database open resetlogs;
                                                                                                                  
Database altered.
                                                                                                                  
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.17.0.0.0
6、修改完dbname后,需要重新创建密码文件
-- 切换到密码文件位置
[oracle@database-001 ~]$ cd $ORACLE_HOME/dbs
-- 删除密码文件
[oracle@database-001 dbs]$ rm -rf orapwdcpfardb
-- 删除修改前db_name相关文件
[oracle@database-001 dbs]$ rm -rf initdcpfardb.ora_bak lkDCPFAREI 
-- 创建密码文件
[oracle@database-001 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwdcpfardb password=Fare1n*land entries=16 force=y
-- 删除修改前的静态文件
[oracle@database-001 dbs]$ rm -rf initdcpfardb.ora
-- 重新创建静态文件、修改sys和system的密码
[oracle@database-001 ~]$ export ORACLE_SID=dcpfardb
[oracle@database-001 ~]$ sqlplus / as sysdba
SQL> create pfile from spfile;

SQL> select instance_name,status from v$instance;
SQL> 
set linesize 1024
select * from v$version;

SQL> alter user sys identified by "password";
User altered.
                                                                                                                                    
SQL> alter user system identified by "password";
User altered.

SQL> 
 7、全库备份
-- 由于修改完dbname,后 ,dbID 发生了改变,需要全库做个备份
[oracle@pet-datalex-ecs-database-001 ~]$ rman target /
RMAN> run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
sql 'alter system archive log current';
backup full database filesperset 20 format '/oracle/rman/full_%d_%T_%s_%p';
sql 'alter system archive log current';
backup archivelog all format '/oracle/rman/arch_%d_%T_%s_%p';
backup current controlfile format '/oracle/rman/ctl_%d_%T_%s_%p';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
修改后:
SQL> show parameter name
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
cdb_cluster_name                     string
cell_offloadgroup_name               string
db_file_name_convert                 string
db_name                              string      dcpfardb
db_unique_name                       string      dcpfardb
global_names                         boolean     FALSE
lock_name_space                      string
log_file_name_convert                string
pdb_file_name_convert                string
processor_group_name                 string
                                                                                                                  
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      dcpfardb
SQL> 

 

至此,数据库db_name 修改完成

8、修改完db_name后,rman登录报了如下错误
[oracle@database-001 ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Mon Nov 7 17:15:54 2022
Version 19.17.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
PL/SQL package SYS.DBMS_BACKUP_RESTORE version 19.16.00.00 in TARGET database is not current
PL/SQL package SYS.DBMS_RCVMAN version 19.16.00.00 in TARGET database is not current
connected to target database: DCPFARDB (DBID=2411995666)

*********************************************************************************************************************
PL/SQL package SYS.DBMS_BACKUP_RESTORE version 19.16.00.00 in TARGET database is not current
PL/SQL package SYS.DBMS_RCVMAN version 19.16.00.00 in TARGET database is not current
*********************************************************************************************************************

-- 报了上面的错误,是因为版本没有更新的原因
RMAN> 
 解决方法:
上面报错解决方案如下:
[oracle@pet-datalex-ecs-database-001 ~]$ export ORACLE_SID=dcpfardb
[oracle@pet-datalex-ecs-database-001 ~]$ sqlplus / as sysdba
-- 切换日志
SQL> alter system switch logfile;
                                                                                                                  
System altered.
                                                                                                                  
SQL> /
                                                                                                                  
System altered.
                                                                                                                  
SQL> /
                                                                                                                  
System altered.
         
-- 将缓冲数据写入到数据文件中                                                                                                        
SQL> alter system checkpoint;
                                                                                                                  
System altered.
                                                                                                                  
SQL> /
                                                                                                                  
System altered.
                                                                                                                  
SQL> /
                                                                                                                  
System altered.
                                                                                                                  

-- 然后执行下面的四个sql
SQL> @$ORACLE_HOME/rdbms/admin/dbmsrman.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtrmns.plb   
SQL> @$ORACLE_HOME/rdbms/admin/dbmsbkrs.sql 
SQL> @$ORACLE_HOME/rdbms/admin/prvtbkrs.plb
SQL> exit

然后, 重新rman登录就好了

[oracle@database-001 ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Mon Nov 7 17:15:54 2022
Version 19.17.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DCPFARDB (DBID=2411995666)

RMAN> 


原文地址:https://blog.csdn.net/weixin_69821704/article/details/140615033

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!