miércoles, 11 de julio de 2012

RMAN : Como Borrar una base de datos

En un ambiente en donde tienes que estar refrescando base de datos seguido, una de las mejores maneras y mas seguras de borrar los archivos pertenecientes a la base de datos que vas a refrescar es con el comando DROP DATABASE.

Si estas en un ambiente de RAC, lo primero que tienes que hacer es cambiar el parámetro de cluster_database a FALSO y una vez que lo hayas hecho, apaga la base de datos.

oracle@servidor1.oracleenespanol.blogspot.com [TESTDB1] /home/oracle
oracle $ sqlplus

SQL*Plus: Release 11.2.0.3.0 Production on Wed Jul 11 22:30:21 2012

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Enter user-name: /as sysdba

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

TESTDB1 >alter system set cluster_database=FALSE scope=spfile;

System altered.

TESTDB1 >exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

oracle@servidor1.oracleenespanol.blogspot.com [TESTDB1] /home/oracle
oracle $ srvctl stop database -d TESTDB

oracle@servidor1.oracleenespanol.blogspot.com [TESTDB1] /home/oracle
oracle $ srvctl status database -d TESTDB
Instance TESTDB1 is not running on node servidor1
Instance TESTDB2 is not running on node servidor2

Ya que cerraste la base de datos,asegurate de que tienes las variables de ambiente correctas y  vamos a abrirla en modo MOUNT y de ahí a habilitar una sesión restringida.

oracle@servidor1.oracleenespanol.blogspot.com [TESTDB1] /home/oracle
oracle $ . $HOME/TESTDB

oracle@servidor1.oracleenespanol.blogspot.com [TESTDB1] /home/oracle
oracle $ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Wed Jul 11 22:36:08 2012

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup mount;

Oracle instance started
database mounted

Total System Global Area    2622255104 bytes

Fixed Size                     2231232 bytes
Variable Size                637535296 bytes
Database Buffers            1962934272 bytes
Redo Buffers                  19554304 bytes

RMAN> SQL 'ALTER SYSTEM ENABLE RESTRICTED SESSION';

using target database control file instead of recovery catalog
sql statement: ALTER SYSTEM ENABLE RESTRICTED SESSION

Ya lo unico que nos queda por hacer es tirar la base de datos, a mi no me gusta hacerlo con NOPROMPT, ya que es la ultima oportunidad que vas a tener para asegurarte de que estas borrando la base de datos correcta, pero ahora si en gustos se rompen generos.

RMAN> DROP DATABASE INCLUDING BACKUPS;

database name is "TESTDB" and DBID is 1743232258

Do you really want to drop all backups and the database (enter YES or NO)?YES


allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=62 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=82 device type=DISK

List of Backup Pieces
BP Key  BS Key  Pc# Cp# Status      Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1       1       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_3_788480833
2       2       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_4_788480833
3       3       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_5_788480834
4       4       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_2_788480832
5       5       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_6_788480835
6       6       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_7_788480837
7       7       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_8_788480838
8       8       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_9_788480839
9       9       1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_1_788480832
10      10      1   1   AVAILABLE   DISK        /copy01/TESTDB/full/TESTDB_HOT_07012012_1_10_788480839
11      11      1   1   AVAILABLE   DISK        /copy01/TESTDB/control/TESTDB_07_01_2012_788480872.ctl
12      12      1   1   AVAILABLE   DISK        /copy01/TESTDB/control/c-1743232258-20120701-00
13      13      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_16_788480924
14      14      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_17_788480924
15      15      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_18_788480926
16      16      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_15_788480923
17      17      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_13_788480923
18      18      1   1   AVAILABLE   DISK        /copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_14_788480923
19      19      1   1   AVAILABLE   DISK        /copy01/TESTDB/control/c-1743232258-20120701-01
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_3_788480833 RECID=1 STAMP=788480834
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_4_788480833 RECID=2 STAMP=788480834
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_5_788480834 RECID=3 STAMP=788480836
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_2_788480832 RECID=4 STAMP=788480833
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_6_788480835 RECID=5 STAMP=788480838
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_7_788480837 RECID=6 STAMP=788480838
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_8_788480838 RECID=7 STAMP=788480839
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_9_788480839 RECID=8 STAMP=788480839
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_1_788480832 RECID=9 STAMP=788480832
deleted backup piece
backup piece handle=/copy01/TESTDB/full/TESTDB_HOT_07012012_1_10_788480839 RECID=10 STAMP=788480840
deleted backup piece
backup piece handle=/copy01/TESTDB/control/TESTDB_07_01_2012_788480872.ctl RECID=11 STAMP=788480875
deleted backup piece
backup piece handle=/copy01/TESTDB/control/c-1743232258-20120701-00 RECID=12 STAMP=788480881
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_16_788480924 RECID=13 STAMP=788480924
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_17_788480924 RECID=14 STAMP=788480924
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_18_788480926 RECID=15 STAMP=788480926
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_15_788480923 RECID=16 STAMP=788480924
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_13_788480923 RECID=17 STAMP=788480923
deleted backup piece
backup piece handle=/copy01/TESTDB/arch/TESTDB_ARCH_07012012_1_14_788480923 RECID=18 STAMP=788480923
deleted backup piece
backup piece handle=/copy01/TESTDB/control/c-1743232258-20120701-01 RECID=19 STAMP=788480947
Deleted 19 objects


released channel: ORA_DISK_1
released channel: ORA_DISK_2
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=62 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=82 device type=DISK
specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any control file copy in the repository
List of Archived Log Copies for database with db_unique_name TESTDB
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - ---------
14      2    4       A 11-JUL-12
        Name: +ARCH/TESTDB/archivelog/TESTDB_4_2_788478082.dbf

deleted archived log
archived log file name=+ARCH/TESTDB/archivelog/TESTDB_4_2_788478082.dbf RECID=14 STAMP=788481092
Deleted 1 objects


database name is "TESTDB" and DBID is 1743232258
database dropped