Performing PITR in a Pugglabe Database with Local UNDO

Este artigo aborda a execução de um Point-in-Time Recovery em um PDB específico, mas considerando que o ambiente esteja com a configuração da LOCAL UNDO habilitada. Para os casos onde a UNDO está compartilhada entre CDB$ROOT e demais PDBs (obrigatoriamente da 12.1), a abordagem desta implementação é diferente e será tratada em outro momento.

Validado se nosso ambiente está configurado com LOCAL UNDO:

[oracle@oel7 dados]$ sqlplus / as sysdba
 
SQL*Plus: Release 19.0.0.0.0 - Production on Wed May 26 05:03:43 2021
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
 
SQL> col PROPERTY_NAME format a25
SQL> col PROPERTY_VALUE format a10
SQL> SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'LOCAL_UNDO_ENABLED';
 
PROPERTY_NAME             PROPERTY_V
------------------------- ----------
LOCAL_UNDO_ENABLED        TRUE

Realizando um backup do CDB e seus PDBs:

[oracle@oel7 dados]$ rman target /
 
Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 26 05:04:14 2021
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: ASWN (DBID=3842619206)
 
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
 
 
Starting backup at 26-MAY-21
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=7 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=1 STAMP=1073538273
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/backupset/2021_05_26/o1_mf_annnn_TAG20210526T050434_jbw08lyp_.bkp tag=TAG20210526T050434 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 26-MAY-21
 
Starting backup at 26-MAY-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=00001 name=/oracle/dados/ASWN/datafile/o1_mf_system_jbvxxtmm_.dbf
input datafile file number=00003 name=/oracle/dados/ASWN/datafile/o1_mf_sysaux_jbvy05r2_.dbf
input datafile file number=00004 name=/oracle/dados/ASWN/datafile/o1_mf_undotbs1_jbvy18tj_.dbf
input datafile file number=00007 name=/oracle/dados/ASWN/datafile/o1_mf_users_jbvy1cwc_.dbf
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/backupset/2021_05_26/o1_mf_nnndf_TAG20210526T050442_jbw08tbv_.bkp tag=TAG20210526T050442 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_sysaux_jbw01lh8_.dbf
input datafile file number=00009 name=/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_system_jbw01lh3_.dbf
input datafile file number=00011 name=/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_undotbs1_jbw01lh9_.dbf
input datafile file number=00012 name=/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_users_jbw042o2_.dbf
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_26/o1_mf_nnndf_TAG20210526T050442_jbw0cjcr_.bkp tag=TAG20210526T050442 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/oracle/dados/ASWN/datafile/o1_mf_sysaux_jbvyhq7z_.dbf
input datafile file number=00005 name=/oracle/dados/ASWN/datafile/o1_mf_system_jbvyhq5r_.dbf
input datafile file number=00008 name=/oracle/dados/ASWN/datafile/o1_mf_undotbs1_jbvyhq89_.dbf
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/C337AF22DF9E22E0E0536C00A8C0D589/backupset/2021_05_26/o1_mf_nnndf_TAG20210526T050442_jbw0dm45_.bkp tag=TAG20210526T050442 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 26-MAY-21
 
Starting backup at 26-MAY-21
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=2 STAMP=1073538438
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/backupset/2021_05_26/o1_mf_annnn_TAG20210526T050718_jbw0fpyn_.bkp tag=TAG20210526T050718 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 26-MAY-21
 
Starting Control File and SPFILE Autobackup at 26-MAY-21
piece handle=/oracle/fra/ASWN/autobackup/2021_05_26/o1_mf_s_1073538440_jbw0fswh_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-MAY-21

Em nosso PDB que será usado como teste, vamos criar uma tabela conforme abaixo, já populando-a:

[oracle@quiasma ASWAN]$ sqlplus / as sysdba
 
SQL*Plus: Release 18.0.0.0.0 - Production on Tue May 25 04:30:06 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle.  All rights reserved.
 
 
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.13.0.0.0
 
SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> CREATE TABLE BSS1.TESTE1 (DESCRICAO VARCHAR2(20));
 
Table created.
 
SQL> INSERT INTO BSS1.TESTE1 (DESCRICAO) VALUES ('PITR PDB 1');
 
1 row created.
 
SQL> INSERT INTO BSS1.TESTE1 (DESCRICAO) VALUES ('PITR PDB 2');
 
1 row created.
 
SQL> INSERT INTO BSS1.TESTE1 (DESCRICAO) VALUES ('PITR PDB 3');
 
1 row created.
 
SQL> COMMIT;
 
Commit complete.
 
SQL> SELECT * FROM BSS1.TESTE1;
 
DESCRICAO
--------------------
PITR PDB 1
PITR PDB 2
PITR PDB 3

Gerando alguns archives e realizando o backup dos mesmos:

SQL> conn / as sysdba
Connected.
SQL> ALTER SYSTEM SWITCH LOGFILE;
 
System altered.
 
SQL> /
 
System altered.

Verificando o atual SCN do banco:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
 
CURRENT_SCN
-----------
    2140560

Disparando um backup dos archivelogs:

RMAN> BACKUP ARCHIVELOG ALL;
 
Starting backup at 26-MAY-21
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=1 STAMP=1073538273
input archived log thread=1 sequence=7 RECID=2 STAMP=1073538438
input archived log thread=1 sequence=8 RECID=3 STAMP=1073538583
input archived log thread=1 sequence=9 RECID=4 STAMP=1073538589
input archived log thread=1 sequence=10 RECID=5 STAMP=1073538671
channel ORA_DISK_1: starting piece 1 at 26-MAY-21
channel ORA_DISK_1: finished piece 1 at 26-MAY-21
piece handle=/oracle/fra/ASWN/backupset/2021_05_26/o1_mf_annnn_TAG20210526T051111_jbw0nzr8_.bkp tag=TAG20210526T051111 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 26-MAY-21
 
Starting Control File and SPFILE Autobackup at 26-MAY-21
piece handle=/oracle/fra/ASWN/autobackup/2021_05_26/o1_mf_s_1073538678_jbw0o71n_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-MAY-21

Fazendo o delete da tabela para simularmos a situação que justifique o PITR (claro que poderíamos usar o Flashback também, mas não é este o cerne deste artigo):

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> DELETE BSS1.TESTE1;
 
3 rows deleted.
 
SQL> COMMIT;
 
Commit complete.
 
SQL> SELECT COUNT(*) FROM BSS1.TESTE1;
 
  COUNT(*)
----------
         0

A parte legal deste recurso de recuperação de um PDB em específico é que o CDB$ROOT e outros PDBs do ambiente não são impactos e não sofrem indisponibilidade. Vamos baixar o nosso pluggable database:

SQL> conn / as sysdba
Connected.
SQL> ALTER PLUGGABLE DATABASE HIPOFISE1 CLOSE IMMEDIATE;
 
Pluggable database altered.

Agora podemos disparar os comandos de restore e recover apenas do PDB, respeitando o número de SCN informado, conforme exemplo abaixo:

[oracle@oel7 dados]$ rman target /
 
Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 26 05:12:40 2021
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database: ASWN (DBID=3842619206)
 
RMAN> RUN {
        SET UNTIL SCN=2140560;
        RESTORE PLUGGABLE DATABASE HIPOFISE1;
        RECOVER PLUGGABLE DATABASE HIPOFISE1;
}2> 3> 4> 5>
 
executing command: SET until clause
 
Starting restore at 26-MAY-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=459 device type=DISK
 
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00009 to /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_system_jbw01lh3_.dbf
channel ORA_DISK_1: restoring datafile 00010 to /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_sysaux_jbw01lh8_.dbf
channel ORA_DISK_1: restoring datafile 00011 to /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_undotbs1_jbw01lh9_.dbf
channel ORA_DISK_1: restoring datafile 00012 to /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_users_jbw042o2_.dbf
channel ORA_DISK_1: reading from backup piece /oracle/fra/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_26/o1_mf_nnndf_TAG20210526T050442_jbw0cjcr_.bkp
channel ORA_DISK_1: piece handle=/oracle/fra/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_26/o1_mf_nnndf_TAG20210526T050442_jbw0cjcr_.bkp tag=TAG20210526T050442
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 26-MAY-21
 
Starting recover at 26-MAY-21
using channel ORA_DISK_1
 
 
starting media recovery
 
archived log for thread 1 with sequence 7 is already on disk as file /oracle/archives/1_7_1073536073.dbf
archived log for thread 1 with sequence 8 is already on disk as file /oracle/archives/1_8_1073536073.dbf
archived log for thread 1 with sequence 9 is already on disk as file /oracle/archives/1_9_1073536073.dbf
archived log for thread 1 with sequence 10 is already on disk as file /oracle/archives/1_10_1073536073.dbf
media recovery complete, elapsed time: 00:00:01
Finished recover at 26-MAY-21

Abrindo o PDB em RESETLOGS:

RMAN> ALTER PLUGGABLE DATABASE HIPOFISE1 OPEN RESETLOGS;
 
Statement processed

Agora podemos validar se nossa tabela de teste está disponível para uso após a recuperação do PDB:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> SELECT * FROM BSS1.TESTE1;
 
DESCRICAO
--------------------
PITR PDB 1
PITR PDB 2
PITR PDB 3

Caso o procedimento seja realizado em um ambiente corporativo, após um PITR é sempre indicado realizar um backup FULL do ambiente.

Consideração adicional

As etapas deste artigo foram inicialmente testadas em um banco de dados 18.13, porém no momento de realizar o restore/recover do PDB, o seguinte erro era reportado:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/20/2021 04:48:55
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 11 found to restore
RMAN-06023: no backup or copy of datafile 10 found to restore
RMAN-06023: no backup or copy of datafile 9 found to restore

Obviamente acreditei que fosse por conta de algum pormenor técnico, então garanti via LIST que os datafiles possuíam backup. Achei algumas notas também relatando um tipo de issue quando a FRA é usada. Realizei novos testes sem utilizar a FRA e o erro persistia. Mudei também o incarnation do banco de dados, e também não foi resolvido. Encontrei até outra nota mencionando um Bug relacionado com Tablespace PITR para PDBs, e que o Workaroud mencionava a necessidade de se usar catálogo de backup. Assim fiz, e o erro persistia. Após compartilhar a situação em um grupo de DBAs, me foi sugerido realizar um teste, restaurando o PDB, e só depois no bloco RUN fazer o recover com o SCN desejado. O restore executou com sucesso, mas ao tentar fazer o recover, um ORA-600 é reportado. Como já estava no último PSU da versão 18C e não encontrei nenhuma nota de referência, o indicado seria abrir um chamado na Oracle, mas por ser apenas ambiente de laboratório, não pude fazer isso. Mas vale a menção desta experiência para os amigos que venham a passar pelo mesmo caso.

Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laboratório pessoal para fins de aprendizado.

Leave a Comment

Your email address will not be published.