blog Oracle blog in Spanish

Cambiar el DBID y el nombre de una Base de datos (DB_NAME) con DBNEWID

DBNEWID es una utilidad de base de datos que te permite cambiar el identificador interno de una base de datos (DBID) y el nombre de la base de datos (DBNAME). Puedes cambiar únicamente el DBID, el DBNAME, o puedes cambiar ambos, el DBID y el DBNAME.

Esta acción antes de la aparición de la utilidad DBNEWID, se realizaba recreando el archivo de control (controlfile). Sin embargo no permitía cambiar el identificador único (DBID), con lo que no se podían registrar en el repositorio de RMAN la base de datos original y la base de datos copiada manualmente. Este problema se ha resuelto con la utilidad DBNEWID.

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 – Ejecutamos el comando 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 – 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 Database 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 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.

Oracle ACE