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:
Cuando se cambia el DBID de una base de datos, todos los backups y los archive logs de esta base de datos quedan inutilizables, ya que se trata de una base de datos diferente. La base de datos se abre con resetlogs, con lo que se recrean los ficheros de redo logs online y se resetea la secuencia, por tanto, una vez cambiado el DBID, se aconseja cómo primer paso realizar un backup de la base de datos. Si únicamente cambias el DBNAME, no se requiere abrir la base de datos con la opción RESETLOGS, por lo que las copias de seguridad y archivados no se invalidan. En este caso, deberás cambiar el DB_NAME en el fichero .init, haciendo referencia la nuevo nombre, y muy posiblemente recrear el fichero de password, esto puede influir en una restauración de una copia de seguridad anterior al cambio de nombre.
Si cambias el DBID de una base de datos primaria, en un entorno de data guard, la base de datos de STANDBY debe de recrearse.
En entornos RAC, antes de lanzar el comando, debes hacer un shutdown de todas las instancias, y hacer un startup de una sola instancia con el parámetro 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- Cambiamos el nombre de la nueva base de datos en el spfile.
5- Recreamos el fichero de password de la nueva base de datos.
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 Enterprise 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@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;
Recreamos el fichero de password, de la nueva base de datos:
cd $ORACLE_HOME/dbs
orapwd file=orapwnewdb password=password entries=10
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.





