Post

Visualizzazione dei post da marzo, 2021

visualizzare errore ORA -

Gli errori ORA- possono essere visualizzati da lina di comando usando l'utlity " oerr"   La sintassi è la seguente $ oerr ora <number> Vediamo un esempio [oracle@oratest log]$ oerr ora 00230 00230, 00000, "operation disallowed: snapshot controlfile enqueue unavailable" // *Cause: The attempted operation cannot be executed at this time because // another process currently holds the snapshot controlfile enqueue. // *Action: Retry the operation after the concurrent operation that is holding // the snapshot controlfile enqueue terminates.

Block Media Recovery - DATA RECOVERY ADVISOR

RCATPDB è il pdb che contiene Rman Cataolog e ha come db registrato il container db CKULAB01  Creiamo sul pdb PKULAB01 del container CKULAB01 una tabella sotto l'utente "bat". [oracle@coslab05 PKULAB01]$ sqlplus bat/man@PKULAB01 SQL> create tablespace tbs_bat datafile '/u01/app/oracle/oradata/CKULAB01/PKULAB01/tbs_bat01.dbf' size  1M autoextend on next 5M maxsize 3M; SQL> select count(*) from bat.archam; COUNT(*) -------------- 113664 Creare un data block corruction : aprire il data file "tbs_bat01.df" ed inserire delle stringhe. # vi /u01/app/oracle/oradata/CKULAB01/PKULAB01/tbs_bat01.dbf [oracle@coslab05 PKULAB01]$ sqlplus bat/man@PKULAB01 SQL> select count(*) from bat.archam; select count(*) from bat.archam * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 12, block # 10) ORA-01110: data file 12: '/u01/app/oracle/oradata/CKULAB01/PKULAB01/tbs_bat01.dbf' Ricolleghiamoci al Catalog. [oracle@coslab05 admin]$ rman targ

Tablespace e Table Point in Time Recovery

 Creaimo una directory ausiliare per effettuare il "poit in time recovery". [oracle@primary ~]$ mkdir /home/oracle/tspitr Collegarsi al pdb che contiene una tabella che vogliamo cancellare e poi recuperare . [oracle@primary ~]$ sqlplus bat/man@pdb1 SQL> select count(*) from archam;   COUNT(*) ----------       1025 SQL> select current_scn from v$database; CURRENT_SCN -----------------------------     2863093                          ------->  valore a cui volgiamo effettuare il restore. SQL> conn bat/man@pdb1 SQL> delete from archam; 1025 rows deleted. SQL> commit;  Collegarsi al catalogo con RMAN ed effettuare il restore della tabella until time o scn. [oracle@primary ~]$ rman target / catalog rcatown/rcatown@rcatpdb Recovery Manager: Release 12.2.0.1.0 - Production on Mon Mar 22 15:32:36 2021 Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved. connected to target database: ORCL (DBID=1590558615) connected to recovery catalog datab

Database Point-in-Time Recovery

Il database target è "primary" mentre il catalogo è installato su un pdb del database "rmancat". Colleghiamoci al db Primary ed effettauiamo uno switch dei redolog file e poi uno shutdown. SQL> alter system switch logfile; SQL> SHUTDOWN IMMEDIATE; Riavviamo il db in stato mount ed efftuiamo il backup del database. [oracle@primary ~]$ rman target / catalog rcatown/rcatown@rcatpdb Recovery Manager: Release 12.2.0.1.0 - Production on Mon Mar 22 11:51:53 2021 Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved. connected to target database: ORCL (DBID=1590558615, not open ) connected to recovery catalog database RMAN> backup database plus archivelog; Per verificare se è possibile efffettuare il restore di uno specifico file o set di file da un backup. RMAN> Restore Database validate; Se terminata con successo risaliamo ai file usati per il restore del db. RMAN> Restore Database preview Summary; Starting restore at 22-MAR-21 using

Restore e Recover Database

Il db "primary" è un container mentre il pluggable database che contiene il catalogo, su un altro server, è "rcatpdb" e il pdb che contiene il darafile 23 è "pdb1". [oracle@rmancat ~]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb Recovery Manager: Release 12.2.0.1.0 - Production on Thu Mar 18 16:17:50 2021 Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved. connected to target database: ORCL (DBID=1590558615) connected to recovery catalog database Vediamo la lista del backup dei datafile permaenti e temporanei del root container e dei pdb. RMAN> report schema; Report of database schema for database with db_unique_name ORCL List of Permanent Datafiles =========================== File Size(MB) Tablespace           RB segs Datafile Name ---- -------- -------------------- ------- ------------------------ 1    800      SYSTEM               YES     /u01/app/oracle/oradata/orcl/system01.dbf 3    550      SYSAUX     

Numero righe delle tabelle

 Di seguito uno script sql che estrae il numero di righe di ogni tabella. $ vi count_row_table.sql SET SERVEROUTPUT ON spool count_row_table.log DECLARE val NUMBER; BEGIN FOR I IN ( select TABLE_NAME from dba_tables where owner='A20' and table_name IN ( 'T11R_ALIA','T1R_MGRU','T1119R_PFIS','T1123V_MPAR_ALIA_PFIS','T1132R_GOVE' ,'T1134R_GRUP','T1141R_OPAR','T1143V_ALIA_PFIS_MPAR','T1350R_OMON_IOT')          ) LOOP EXECUTE IMMEDIATE 'SELECT count(*) FROM ' || i.table_name INTO val; DBMS_OUTPUT.PUT_LINE (i.table_name || ' ==> ' || val ); END LOOP; END; / spool off exit

Restore e Recover Pluggable Database

Il db "primary" è un container mentre il pluggable database che contiene il catalogo, su un altro server, è "rcatpdb" e il pdb che contiene il darafile 23 è "pdb1". [oracle@rmancat admin]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb RMAN> validate pluggable database pdb1; Starting validate at 11-MAR-21 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=278 device type=DISK RMAN-06169: could not read file header for datafile 23 error reason 5 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of validate command at 03/11/2021 16:51:34 RMAN-06056: could not access datafile 23 Collegarsi al container database "primary" e chiudere il pdb. SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> alter pluggable database p

Restore e Recover di un Tablespace

 Supponiamo che il datafile 24 del database "primary" sia stato corrotto. Il db  "primary" è un container mentre il pluggable database che contiene il catalogo, su un altro server,  è "rcatpdb" e il pdb che contiene il darafile 24 è "pdb1". [oracle@rmancat admin]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb RMAN> list failure; Database Role: PRIMARY no failures found that match specification Il comando precedente non rileva errori, allora proviamo a validare il datafile 24. RMAN> validate datafile 24; Starting validate at 11-MAR-21 using channel ORA_DISK_1 channel ORA_DISK_1: starting validation of datafile channel ORA_DISK_1: specifying datafile(s) for validation RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03009: failure of validate command on ORA

Restore e Rocover di un Datafile

Supponiamo di aver cancellato un datafile sul database "primary" per il quale è stato fatto un backup. Il database è in stato open Collegarsi tramire RMAN dal db Catalog. [oracle@rmancat ~]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb RMAN> LIST FAILURE; Database Role: PRIMARY List of Database Failures ========================= Failure ID Priority Status    Time Detected Summary ---------- -------- --------- ------------- ------- 2542       HIGH     OPEN      11-MAR-21     One or more non-system datafiles are missing RMAN> validate database; Starting validate at 11-MAR-21 using channel ORA_DISK_1 RMAN-06169: could not read file header for datafile 23 error reason 5 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of validate command at 03/11/2021 14:41:59 RMAN-06056:

Validate Backup

Collegarsi al db soggetto a backup dal server contentente il catalogo. [oracle@rmancat ~]$ rman target sys/system@primary connect catalog rcatown/rcatown@rcatpdb Per validare i backup  RMAN> validate database; Per validare i backupset RMAN> validate backupset 4957; Per validare i datafile RMAN> validate datafile 20 block 10; Per verificare che tutti i file del database e gli archivelog possono essere backuppati. Controlla se i file fisici sono corrotti. RMAN> Backup validate database archivelog all; Come prima ma in più controlla se i file sono corrotti a livello logico. RMAN> Backup validate CHECK LOGICAL database archivelog all; Introdotto dalla 11g questo comanco serve per verificare l'integrità dei backup su disco o tape. Individua blocchi corrotti nel database e quindi se è possibile efffettuare il restore di uno specifico file o set di file da un backup. RMAN> Restore Database validate; RMAN> Restore Archivelog all validate; Per validae il root Databaseo

Data Recovery Advisor

 Data Recovery Advisor è un tool Oracle che in automatico diagnostica data faulire e fornisce le opportune opzioni di ripristino. Effettuaimo il backup di  un tablespace del pluggable database pdb1 [oracle@rmancat ~]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb RMAN> BACKUP TABLESPACE pdb1:TBS_BAT TAG 'repair_test'; Starting backup at 01-MAR-21 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00023 name=/u01/app/oracle/oradata/orcl/pdb1/tbs_bat01,dbf input datafile file number=00024 name=/u01/app/oracle/oradata/orcl/pdb1/tbs_bat02.df channel ORA_DISK_1: starting piece 1 at 01-MAR-21 channel ORA_DISK_1: finished piece 1 at 01-MAR-21 piece handle=/u01/app/oracle/fast_recovery_area/orcl/ORCL/B9BBEBE636451CD1E053C68E670A3A69/backupset/2021_03_01/o1_mf_nnndf_REPAIR_TEST_j3t4oo4r_.bkp tag=REPAIR_TEST comment=NONE channel ORA_DISK_1: backup set comple

RMAN Stored Scripts

Gli script RMAN possono essere salvati all'interno del catalog inveche che su file system. Collegarsi al catalogo dal db che contiene RMAN catalog che nell'esempio è un pluggable database. [oracle@rmancat ~]$ rman target sys/system@primary catalog rcatown/rcatown@rcatpdb RMAN>  CREATE  SCRIPT full_backup  { backup database plus archivelog;} RMAN> CREATE GLOBAL SCRIPT global_full_backup { BACKUP DATABASE PLUS ARCHIVELOG; DELETE OBSOLETE; } Per vedere la lista degli script. RMAN> LIST SCRIPT NAMES; List of Stored Scripts in Recovery Catalog Scripts of Target Database ORCL Script Name Description ----------------------------------------------------------------------- full_backup Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup Per vedere il conenuto dello script. RMAN> print script global_full_backup; printing stored global script: global_full_backup { BACKUP DATABASE PLUS ARC