DBNEWID is a database utility that allows you to change the internal identifier of a database (DBID) and the database name (DBNAME). You can change only the DBID, the DBNAME, or you can change both the DBID and the DBNAME.
Before the appearance of the DBNEWID utility, this action was performed by recreating the control file (controlfile). However, it did not allow changing the unique identifier (DBID), so the original database and the manually copied database could not be registered in the RMAN repository. This problem has been solved with the DBNEWID utility.
To perform this test, let's rename the table we restore on the same host, in this entry: https://oracleconraul.com/index.php/2023/09/13/recuperar-base-de-datos-mismo-host-con-rman/
First of all, I advise, that before performing this process you have a backup of the database before renaming the database, its DBID or both.
It should be noted, that the name change, and especially the DBID is a complex and serious procedure, since among other things, the change produces the following:
When the DBID of a database is changed, all backups and archive logs of this database become unusable, since it is a different database. The database is opened with resetlogs, which recreates the online redo log files and resets the sequence, therefore, once the DBID has been changed, it is advisable to perform a backup of the database as a first step. If you only change the DBNAME, it is not required to open the database with the RESETLOGS option, so backups and archives are not invalidated. In this case, you must change the DB_NAME in the .init file, referencing the new name, and most likely recreate the password file, this may influence a restore of a backup prior to the name change.
If you change the DBID of a primary database, in a data guard environment, the STANDBY database must be recreated.
In RAC environments, before launching the command, you must do a shutdown of all instances, and do a single instance startup with the parameter CLUSTER_DATABASE=FALSE.
Steps:
1- We load the environment variables of the database to rename/dbid.
2- We stop the database (shutdown immediate), and mount the database (startup mount).
3 - Execute the command DBNEWID
$ nid TARGET=SYS/<password>@<service> DBNAME=<NEW DB name> (tnsnames)
or
nid TARGET=SYS/<password> DBNAME=<NEW DB name>
4- We change the name of the new database in the spfile.
5- We recreate the password file of the new database.
Command execution:
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0.0 - Production on Wed Sep 20 12:00:13 2023
Version 19.3.0.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0.0 - Production
Version 19.3.0.0.0.0
SQL> show parameter uniq
NAME TYPE VALUE
db_unique_name string testcopy
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup mount
[oracle@localhost ~]$ nid TARGET=sys/password DBNAME=newdb
Connected to server version 19.3.0
Control Files in database:
/data/testcopy/TESTCOPY/controlfile/o1_mf_lj1qob64_.ctl
Change database ID and database name TEST to NEWDB? (Y/[N]) => Y
Proceeding with operation
Changing database ID from 2359187194 to 3388414278
Changing database name from TEST to NEWDB
Control File /data/testcopy/TESTCOPY/controlfile/o1_mf_lj1qob64_.ctl - modified
Datafile /data/tescopy/TESCOPY/data_D-TEST_TS-SYSTEM_FNO- - dbid changed, wrote new name
Datafile /data/tescopy/TESCOPY/data_D-TEST_TS-SYSAUX_FNO- - dbid changed, wrote new name
Datafile /data/tescopy/TESCOPY/data_D-TEST_TS-UNDOTBS1_FNO- - dbid changed, wrote new name
Datafile /data/tescopy/TESCOPY/data_D-TEST_TS-USERS_FNO- - dbid changed, wrote new name
Datafile /data/test/TEST/datafile/o1_mf_temp_hz8q6jog_.tm - dbid changed, wrote new name
Control File /data/testcopy/TESTCOPY/controlfile/o1_mf_lj1qob64_.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to NEWDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database NEWDB changed to 3388414278.
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.
At this point it is necessary to change the DBNAME in the spfile, otherwise the database will not start because it has a new name.
SQL> alter system set db_name=NEWDB scope=spfile;
Recreation of the password file of the new database:
cd $ORACLE_HOME/dbs
orapwd file=orapwnewdb password=password entries=10
At this point we can open the database with open resetlogs.
SQL> alter database open resetlogs;
We verify that the name has been made correctly:
SQL> select name from v$database;
NAME
******* *******
NEWDB
As stated earlier in this document, at this point it is highly recommended to make a backup of the database, since in case of problems, it is not possible to restore from previous backups.