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, we are going to rename the table we restored on the same host, in this post:
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 you change a database’s DBID, all backups and archive logs for that database become unusable, since it is now a different database. The database is opened with the RESETLOGS option, which recreates the redo log files online resets the sequence; therefore, once the DBID has been changed, it is recommended that you back up the database as a first step. If you only change the DBNAME, you do not need to open the database with the RESETLOGS option, so backups and archive logs remain valid. In this case, you must change the DB_NAME in the .init file to reflect the new name, and you will likely need to recreate the password file; this may affect the restoration of a backup taken before 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 executing the command, you must shut down all instances and then start a single instance with the CLUSTER_DATABASE=FALSE parameter.
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 password the new database.
Execution of commands:
[oracle~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 – Production on Wed Sep 20 12:00:13 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle 19c Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0
SQL> show parameter uniq
NAME TYPE VALUE
db_unique_name string testcopy
SQL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE shut down.
SQL>
SQL>startup mount
[oracle~]$nidpassword
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 the parameter file and generate a new password before restarting.
Database ID for database NEWDB changed to 3388414278.
All previous backups and archived redo logs for this database are unusable.
The database has been shut down; open the database with the RESETLOGS option.
The database name and ID were successfully changed.
DBNEWID – Completed successfully.
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;
We recreate the password file for the new database:
cdORACLE
orapwd file=orapwnewdbpassword
We 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 indicated earlier in this document, at this point it is highly recommended to perform a backup of the database, since it will not be possible to restore from previous backups.





