Cambiar DBNAME y DBID en Oracle database
Este documento tiene como finalidad crear una guía útil para cambiar el DBNAME y el DBID mediante la utilidad NID disponible desde Oracle 9.2
Si cambias el DBID tendrás que abrir la base de datos con un "OPEN RESETLOGS", lo que conlleva la recreación de los redologs y poner la secuencia de los archives a 1. Los anteriores backup serán invalidados
No obstante, puedes cambiar sólo el DBNAME si los efectos secundarios descritos añadiendo el parámetro SETNAME=Y, esto te permite cambiar el DBNAME sin cambiar el DBID.
SQL> select dbid,name,open_mode,activation#,created from v$database; DBID NAME OPEN_MODE ACTIVATION# CREATED ---------- --------- -------------------- ----------- --------- 1423238009 ORCL READ WRITE 1423232377 11-NOV-15
Creamos un pfile nuevo a fin de poder modificarlo:
SQL> create pfile from spfile; File created. SQL> exit Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options [oracle@wcp12cr2_clone ~]$ cd $ORACLE_HOME/dbs [oracle@wcp12cr2_clone dbs]$ ls -ltr total 9836 -rw-r--r--. 1 oracle oinstall 2992 Feb 3 2012 init.ora -rw-r-----. 1 oracle oinstall 24 Nov 11 2015 lkORCL -rw-r-----. 1 oracle oinstall 7680 Nov 11 2015 orapworcl -rw-r-----. 1 oracle oinstall 10043392 Sep 27 07:18 snapcf_orcl.f -rw-rw----. 1 oracle oinstall 1544 Oct 19 00:04 hc_orcl.dat -rw-r-----. 1 oracle oinstall 2560 Oct 19 00:05 spfileorcl.ora -rw-r--r--. 1 oracle oinstall 917 Oct 19 00:14 initorcl.ora
Ahora podemos bajar la base de datos e iniciarla en estado mount con el pfile que previamente hemos creado:
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount pfile=$ORACLE_HOME/dbs/initorcl.ora ORACLE instance started. Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 713032960 bytes Database Buffers 348127232 bytes Redo Buffers 5480448 bytes Database mounted. SQL> exit
Tras esto, podemos ejecutar el comando NID que cambia el DBNAME y el DBID, ponemos en el comando dbname=orclstb que será el nuevo nombre de la BBDD... al ejecutar el comando no nos dará ningún mensaje en caso de ejecutarse correctamente, pero nos dejará un log en logfile=$ORACLE_HOME/log/nid.log.
Recurerda, si no quieres cambiar el DBID debes poner el parámetro SETNAME=Y, así no se recrearán los redologs..
nid target=sys/oracle@orcl dbname=orclstb logfile=$ORACLE_HOME/log/nid.log DBNEWID: Release 12.1.0.1.0 - Production on Thu Oct 19 00:57:25 2017 Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved. Connected to database ORCL (DBID=1423238009) Connected to server version 12.1.0 Control Files in database: /oracle/db/oradata/orcl/control01.ctl /oracle/db/fast_recovery_area/orcl/control02.ctl Changing database ID from 1423238009 to 1140464757 Changing database name from ORCL to ORCLSTB Control File /oracle/db/oradata/orcl/control01.ctl - modified Control File /oracle/db/fast_recovery_area/orcl/control02.ctl - modified Datafile /oracle/db/oradata/orcl/system01.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_ias_opss.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/sysaux01.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/undotbs01.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_webcenter_portlet.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/users01.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_iaswebcenter.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_iasjive.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_svctbl.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_iau.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_mds.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_ocs.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_iasactivities.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/temp01.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_iastemp.db - dbid changed, wrote new name Datafile /oracle/db/oradata/orcl/WCPVM_ocstemp.db - dbid changed, wrote new name Control File /oracle/db/oradata/orcl/control01.ctl - dbid changed, wrote new name Control File /oracle/db/fast_recovery_area/orcl/control02.ctl - dbid changed, wrote new name Instance shut down Database name changed to ORCLSTB. Modify parameter file and generate a new password file before restarting. Database ID for database ORCLSTB changed to 1140464757. 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.
Ahora tenemos que cambiar este parámetro en el initorcl.ora *.db_name='orcl' y ponerlo con el nuevo nombre de la base de datos, es decir *.db_name='orclstb'
luego renombraremos el init.ora con el nuevo DBNAME..
mv $ORACLE_HOME/dbs/initorcl.ora $ORACLE_HOME/dbs/initorclstb.oradespués de esto hacemos startup mount, pero como hemos dicho anteriormente, sino utilizamos el parámetro SETNAME=Y de la utilidad nid, tendremos que hacer un "open resetlogs"
SQL> startup mount pfile=$ORACLE_HOME/dbs/initorclstb.ora ORACLE instance started. Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 713032960 bytes Database Buffers 348127232 bytes Redo Buffers 5480448 bytes Database mounted. SQL> alter database open resetlogs; Database altered. SQL> select dbid,name,open_mode,activation#,created from v$database; DBID NAME OPEN_MODE ACTIVATION# CREATED ---------- --------- -------------------- ----------- --------- 1140464757 ORCLSTB READ WRITE 1140467336 11-NOV-15
ahora generamos el nuevo fichero de password de oracle
export ORACLE_SID=orclstb orapwd file=orapw${ORACLE_SID} password=oracle entries=5
Y finalmente creamos un nuevo spfile desde el pfile del que hemos arrancado y reiniciamos para que tenga efecto:
SQL> create spfile from pfile; File created. SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup; ORACLE instance started. Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 713032960 bytes Database Buffers 348127232 bytes Redo Buffers 5480448 bytes Database mounted. Database opened. SQL>
Comentarios
Publicar un comentario