miércoles, 30 de julio de 2014

list of commands start database orcl

 srvctl start database -d orcl 
srvctl add database -d dbtest -o /u01/app/oracle/product/11.2.0/dbhome_1 --add a database to oracle restart
srvctl start database -d orcl -o mount
srvctl stop database –d orcl -o abort

Flashback Drop table

Flashback Drop table
--Flashing back a table dropped using drop table flashback table times to before drop;--Displays the name of the original table show recyclebin;--To clear the recyclebin of all users in the database, purge --recyclebin as purge dba_recyclebin;--or one user's recyclebin purge recyclebin;

domingo, 27 de julio de 2014

RESTORE Y RECOVER

Comandos RESTORE Y RECOVER de RMAN Restore command: Restaura los archivos desde un respaldo Revoer command: Recupera los archivos restaurados aplicandoles los cambios guardados en los respaldos incrementales y los archivos de redo.

Backup control file to trace

Control File to trace
alter database backup controlfile to trace as'/home/oracle/BACKUP/trace_control.bck';--Crea dos conjuntos de comandos SQL, cada uno crea un nuevo controlfile --y lo usa para abrir la base de datos. El primer script abre la base de --datos con la opción NORESETLOGS y debe ser usado solo sí las versiones --actuales de los logs estan disponibles. STARTUP NOMOUNTCREATE CONTROLFILE REUSE DATABASE "RCAT" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292LOGFILE GROUP 1 '+DATA/rcat/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '+DATA/rcat/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '+DATA/rcat/redo03.log' SIZE 50M BLOCKSIZE 512DATAFILE '+DATA/rcat/system01.dbf', '+DATA/rcat/sysaux01.dbf', '+DATA/rcat/undotbs01.dbf', '+DATA/rcat/users01.dbf', '+DATA/rcat01.dbf'CHARACTER SET AL32UTF8; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE '+FRA'; -- ALTER DATABASE REGISTER LOGFILE '+FRA'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE -- All logs need archiving and a log switch is needed. ALTER SYSTEM ARCHIVE LOG ALL; -- Database can now be opened normally. ALTER DATABASE OPEN; --El segundo script reset logs indica que la base se abrirá --con la opciónn ALTER DATABASE OPEN RESETLOGS esta opción es valida --solo si los online logs no estan disponibles. STARTUP NOMOUNTCREATE CONTROLFILE REUSE DATABASE "RCAT" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292LOGFILE GROUP 1 '+DATA/rcat/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '+DATA/rcat/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '+DATA/rcat/redo03.log' SIZE 50M BLOCKSIZE 512-- STANDBY LOGFILE DATAFILE '+DATA/rcat/system01.dbf', '+DATA/rcat/sysaux01.dbf', '+DATA/rcat/undotbs01.dbf', '+DATA/rcat/users01.dbf', '+DATA/rcat01.dbf'CHARACTER SET AL32UTF8; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE '+FRA'; -- ALTER DATABASE REGISTER LOGFILE '+FRA'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE USING BACKUP CONTROLFILE -- Database can now be opened zeroing the online logs. ALTER DATABASE OPEN RESETLOGS;

sábado, 26 de julio de 2014

Instrucciones utiles

Útiles
#Configurando la base de datos para estar en modo archivelog. . oraenv orclsqlplus /as sysdbaarchive log listshutdown immediatestartup mountalter database archivelog;alter database open; # Cambiando el tamaño de la Flash Recovery Area. show parameter recovery_file_dest_sizeshow parameter recovery_file_destALTER SYSTEM SET db_recovery_file_dest_size = 8G SCOPE=BOTH; #Verificando los archivos de destino.. oraenvorclrman target /show controlfile autobackup;configure controlfile autobackup on;report schema; #lista los datafiles en tu esquema.backup datafile 5; #Configurando la politica de retención.. oraenvorclrman target /show retention policy;configure retention policy to redundancy 1;show retention policy;exit #After creating rcat database with dbca we should do the following tasks #sqlplus sys as sysdba#Enter password: oracle_4U@rcat<<<not displayed#Crear un tablespace llamado RCAT para que guarde el repositorio de datos. CREATE TABLESPACE rcat DATAFILE '+DATA/rcat01.dbf' SIZE 15M;#Crear un usuario propietario del catalogo de recuperacion. CREATE USER rcatowner IDENTIFIED BY oracle_4U DEFAULT TABLESPACE rcat QUOTA unlimited on rcat; #Dar al catalogo de recuperación el role de rcatownerGRANT recovery_catalog_owner to rcatowner;exit #Conectate al catalogo de recuperacion usando RMAN. rman catalog rcatowner@rcat#CREA EL CATALOG DE RECUPERACIÓNcreate catalog;exit #Registra la base de datos ORCL en el catalogo de recuperación que acabase#de crear.oraenvorclrman target / catalog rcatowner@rcatregister database;exit #Respaldando el catalogo de recuperación y la politica de recuperación. oraenvorclrman target sys@rcatshow retention policy;configure retention policy to redundancy 2;backup database;exit # Configura la base de datos rcat para trabajar en modo archivelog. oraenvrcatshutdown immediatestartup mountalter database archivelog;alter database open;. oraenvorclrman target sys@rcatbackup database;exit #Configurando el formato de fecha y hora linux & windowsexport NLS_LANG=american_america.al32utf8export NLS_DATE_FORMAT="yyyy-mm-dd:hh24:mi:ss"#.bashrc#Windowsset NLS_DATE_FORMAT=MON DD, YYYY HH24:MI:SS #habilitando el auto backupcontrol file. oraenvorclrman target sys@rcatoracle_4Ulist backup;show controlfile autobackup;configure controlfile autobackup on;backup archive all;exit #Configurando aparatos para respaldo. oraenvorclrman target / catalog rcatowner@rcatoracle_4Ushow all;#Define un canal para un aparato de cinta que usa la interface test.configure channel device type sbt parms='SBT_LIBRARY=oracle.disksbt, ENV=(BACKUP_DIR=/tape)';backup device type sbt tablespace users; #Creando respaldos incrementales rapidosCONFIGURE CONTROLFILE AUTOBACKUP ON;show controlfile autobackup;CONFIGURE BACKUP OPTIMIZATION ON;show ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;SELECT filename, status, bytesFROM v$block_change_tracking; $. oraenvorcl$ rman target / catalog rcatowner@rcatbackup incremental level 0 database plus archivelog;orbackup device type sbt incremental level 0 database plus archivelog;backup incremental level 1 database plus archivelog;orbackup device type sbt incremental level 1 database plus archivelog; #Cotejando los respaldos con el catalogo de recuperación. . oraenvrman target / catalog rcatowner@rcatRMAN> list backup of datafile 5;$ list backup of datafile 5;#Data file expired si se borro.crosscheck backupset;delete expired backupset; $ list backup of datafile 5; #para ver los respaldos que son obsoletos report obsolete; #para ver que respaldos se han vuelto obsoletos con la redundancia 2 #~sin cambiar la politica de retecion report obsolete redundancy 2; #Para borrar los respaldos obsoletosRMAN> delete noprompt obsolete;#Lista los respaldos que podrian utilizarse para recuperar la base#de datos al estado que tenia hace una hora.RMAN> list backup of archivelog until time 'sysdate-1/24'; #o hace cinco minutosRMAN> list backup of archivelog until time 'sysdate-05/60/24'; #Revisa las copias imagenes de un unico datafile en el tablespace USER.#Report schema para averiguar que numero le corresponde al USERS tablespaceRMAN > report schema;#Lista cualquier copia imagen del datafile 4list copy of datafile 4;#Borra cualquier copia imagen del datafile 4 sí existe.delete copy of datafile 4;#Para simplificar el ambiente de entrenamiento deshabilita #autobakcup on. #Sí hay backup del controlfile rman target /restore controlfile from autobackup;alter database mount;recover database;alter database open resetlogs;alter database open resetlogs;

Oracle-Managed Files (OMF)

Oracle-Managed Files (OMF)

Specify file operations in terms of database objects rather than file names.

ParameterDescription
DB_CREATE_FILE_DESTDefines the location of the default file system directory for data files and temporary files
DB_CREATE_ONLINE_LOG_DEST_n Defines the location for redo log files and control file creation
DB_RECOVERY_FILE_DESTDefault location for the fast recovery area
SQL> ALTER SYSTEM SET DB_CREATE_FILE__DEST '+DATA';
SQL> CREATE TABLESPACE tbs_1;

lunes, 21 de julio de 2014

DB_RECOVERY_FILE_DEST especifica la ubicacion del area de recuperación rapida.
El area de recuperación rápida contiene copias multiplexadas de los archivos de control actuales y los redo logs en línea, además de los archive redo logs, flashback logs, y respaldos de RMAN. Este parametro de inicialización debe  especificarse después del parametro DB_RECOVERY_FILE_DEST_SIZE_n.

DB_CREATE_FILE_DEST
Especifica la ubicacion por default para los oracle managed files. Esta ubicación también es usada como la ubicación como la ubicacion default para los oracle managed files control files y online redo logs sí  ninguna DB_CREATE_FILE_DEST_n esta especificada.

Creando copias imagen
Una copia imagen es una copia clon de un archivo de texto, redo log archivado o un archivo de control. Una copia imagen puede ser creada con el comando  BACKUP AS COPY o con un comando del sistema operativo. Cuando tu creas la copia imagen con el comando de RMAN BACKUP AS COPY, la sesión del servidor valida los bloques en el archivo y graba la información de la copia en el
archivo de control.
Una copia imagen tiene las siguientes caracteristicas.
    *Solo puede ser escrita a disco. Cuando archivos muy grandes son considerados, copiarlos puede tomar largo tiempo, pero el tiempo de restauración se reduce considerablemente porque la copia esta disponible en el disco.
    *Sí los archivos son restaurados a disco, pueden utilizarse  inmediatamente  utilizando el comando SWITCH en RMAN, que es el  equivalente del comando ALTER DATABASE RENAME FILE en SQL.