Realizar um Point-in-Time Recover de PDB que utilize uma área de UNDO compartilhada exige um procedimento um pouco diferente se comparado com Local UNDO. Na 12.1 nossa única opção é o Shared UNDO, mas a partir da 12.2 conseguimos definir isso no momento da criação do banco de dados. Para este artigo, estou criando um banco novo em 19C como Shared UNDO, conforme abaixo:

Com o ambiente disponível, conseguimos validar a condição da UNDO com a consulta abaixo:
[oracle@oel7 PITR]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu May 27 20:48:17 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> ALTER SESSION SET CONTAINER=HIPOFISE1;
Session altered.
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 FALSE
Realizando um backup do CDB e seus PDBs:
[oracle@oel7 PITR]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Thu May 27 20:49:29 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: ASWAN (DBID=1341595825)
RMAN> BACKUP DATABASE PLUS ARCHIVELOG;
Starting backup at 27-MAY-21
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=80 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=1073681379
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_annnn_TAG20210527T204940_jc0d0njh_.bkp tag=TAG20210527T204940 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 27-MAY-21
Starting backup at 27-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/ASWAN/datafile/o1_mf_system_jc0blms9_.dbf
input datafile file number=00003 name=/oracle/dados/ASWAN/datafile/o1_mf_sysaux_jc0bn0x8_.dbf
input datafile file number=00004 name=/oracle/dados/ASWAN/datafile/o1_mf_undotbs1_jc0bnt0l_.dbf
input datafile file number=00007 name=/oracle/dados/ASWAN/datafile/o1_mf_users_jc0bnv2t_.dbf
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d0qt6_.bkp tag=TAG20210527T204943 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
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/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_sysaux_jc0congs_.dbf
input datafile file number=00009 name=/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_system_jc0congn_.dbf
input datafile file number=00011 name=/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_users_jc0cp8xo_.dbf
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d2h2l_.bkp tag=TAG20210527T204943 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
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/ASWAN/datafile/o1_mf_sysaux_jc0bys95_.dbf
input datafile file number=00005 name=/oracle/dados/ASWAN/datafile/o1_mf_system_jc0bys8k_.dbf
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/C3592AD9E96374EFE0536C00A8C0C507/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d385v_.bkp tag=TAG20210527T204943 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
Finished backup at 27-MAY-21
Starting backup at 27-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=1073681489
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_annnn_TAG20210527T205129_jc0d41rq_.bkp tag=TAG20210527T205129 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 27-MAY-21
Starting Control File and SPFILE Autobackup at 27-MAY-21
piece handle=/oracle/fra/ASWAN/autobackup/2021_05_27/o1_mf_s_1073681490_jc0d43r6_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 27-MAY-21
Observando a tabela que usaremos como referência para nosso teste:
SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
Session altered.
SQL> SELECT * FROM BSS1.TESTE1;
DESCRICAO
--------------------
PITR PDB 1
PITR PDB 2
PITR PDB 3
Gerando alguns archives:
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
-----------
2139480
Disparando um backup dos archivelogs:
RMAN> BACKUP ARCHIVELOG ALL;
Starting backup at 27-MAY-21
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 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=1073681379
input archived log thread=1 sequence=7 RECID=2 STAMP=1073681489
input archived log thread=1 sequence=8 RECID=3 STAMP=1073681651
input archived log thread=1 sequence=9 RECID=4 STAMP=1073681652
input archived log thread=1 sequence=10 RECID=5 STAMP=1073681712
channel ORA_DISK_1: starting piece 1 at 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_annnn_TAG20210527T205512_jc0dc0r3_.bkp tag=TAG20210527T205512 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 27-MAY-21
Starting Control File and SPFILE Autobackup at 27-MAY-21
piece handle=/oracle/fra/ASWAN/autobackup/2021_05_27/o1_mf_s_1073681719_jc0dc7yg_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 27-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
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. Devido a Shared UNDO, uma instância auxiliar será criada pelo RMAN, então passamos um diretório de trabalho para que ela possa utilizar durante o processo:
run {
SET UNTIL SCN 2139480;
RESTORE PLUGGABLE DATABASE HIPOFISE1;
RECOVER PLUGGABLE DATABASE HIPOFISE1 AUXILIARY DESTINATION='/oracle/PITR';
}
Log do processo:
RMAN> run {
SET UNTIL SCN 2139480;
RESTORE PLUGGABLE DATABASE HIPOFISE1;
RECOVER PLUGGABLE DATABASE HIPOFISE1 AUXILIARY DESTINATION='/oracle/PITR';
}2> 3> 4> 5>
executing command: SET until clause
Starting restore at 27-MAY-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 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/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_system_jc0congn_.dbf
channel ORA_DISK_1: restoring datafile 00010 to /oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_sysaux_jc0congs_.dbf
channel ORA_DISK_1: restoring datafile 00011 to /oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_users_jc0cp8xo_.dbf
channel ORA_DISK_1: reading from backup piece /oracle/fra/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d2h2l_.bkp
channel ORA_DISK_1: piece handle=/oracle/fra/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d2h2l_.bkp tag=TAG20210527T204943
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 27-MAY-21
Starting recover at 27-MAY-21
using channel ORA_DISK_1
RMAN-05026: warning: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID='iwlo'
initialization parameters used for automatic instance:
db_name=ASWAN
db_unique_name=iwlo_pitr_HIPOFISE1_ASWAN
compatible=19.0.0
db_block_size=8192
db_files=200
diagnostic_dest=/oracle/19.3.0/base
_system_trig_enabled=FALSE
db_domain=localdomain
sga_target=2272M
processes=200
db_create_file_dest=/oracle/PITR
log_archive_dest_1='location=/oracle/PITR'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used
starting up automatic instance ASWAN
Oracle instance started
Total System Global Area 2382363840 bytes
Fixed Size 9137344 bytes
Variable Size 520093696 bytes
Database Buffers 1845493760 bytes
Redo Buffers 7639040 bytes
Automatic instance created
contents of Memory Script:
{
# set requested point in time
set until scn 2139480;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
}
executing Memory Script
executing command: SET until clause
Starting restore at 27-MAY-21
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=34 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /oracle/fra/ASWAN/autobackup/2021_05_27/o1_mf_s_1073681490_jc0d43r6_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fra/ASWAN/autobackup/2021_05_27/o1_mf_s_1073681490_jc0d43r6_.bkp tag=TAG20210527T205130
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/PITR/ASWAN/controlfile/o1_mf_jc0dr6bo_.ctl
Finished restore at 27-MAY-21
sql statement: alter database mount clone database
contents of Memory Script:
{
# set requested point in time
set until scn 2139480;
# switch to valid datafilecopies
switch clone datafile 9 to datafilecopy
"/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_system_jc0congn_.dbf";
switch clone datafile 10 to datafilecopy
"/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_sysaux_jc0congs_.dbf";
switch clone datafile 11 to datafilecopy
"/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_users_jc0cp8xo_.dbf";
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 4 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 7 to new;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 4, 3, 7;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
datafile 9 switched to datafile copy
input datafile copy RECID=4 STAMP=1073682141 file name=/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_system_jc0congn_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=5 STAMP=1073682141 file name=/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_sysaux_jc0congs_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=6 STAMP=1073682141 file name=/oracle/dados/ASWAN/C35954A5800908B7E0536C00A8C0EE5B/datafile/o1_mf_users_jc0cp8xo_.dbf
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 27-MAY-21
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/PITR/ASWAN/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/PITR/ASWAN/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/PITR/ASWAN/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00007 to /oracle/PITR/ASWAN/datafile/o1_mf_users_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d0qt6_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fra/ASWAN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T204943_jc0d0qt6_.bkp tag=TAG20210527T204943
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 27-MAY-21
datafile 1 switched to datafile copy
input datafile copy RECID=11 STAMP=1073682205 file name=/oracle/PITR/ASWAN/datafile/o1_mf_system_jc0drdtr_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=1073682205 file name=/oracle/PITR/ASWAN/datafile/o1_mf_undotbs1_jc0drdvt_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=13 STAMP=1073682205 file name=/oracle/PITR/ASWAN/datafile/o1_mf_sysaux_jc0drdvs_.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=14 STAMP=1073682205 file name=/oracle/PITR/ASWAN/datafile/o1_mf_users_jc0drdvv_.dbf
contents of Memory Script:
{
# set requested point in time
set until scn 2139480;
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 4 online";
sql clone "alter database datafile 3 online";
sql clone 'HIPOFISE1' "alter database datafile
9 online";
sql clone 'HIPOFISE1' "alter database datafile
10 online";
sql clone 'HIPOFISE1' "alter database datafile
11 online";
sql clone "alter database datafile 7 online";
# recover pdb
recover clone database tablespace "SYSTEM", "UNDOTBS1", "SYSAUX", "USERS" pluggable database
'HIPOFISE1' delete archivelog;
sql clone 'alter database open read only';
plsql <<<begin
add_dropped_ts;
end; >>>;
plsql <<<begin
save_pdb_clean_scn;
end; >>>;
# shutdown clone before import
shutdown clone abort
plsql <<<begin
pdbpitr_inspect(pdbname => 'HIPOFISE1');
end; >>>;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 4 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 9 online
sql statement: alter database datafile 10 online
sql statement: alter database datafile 11 online
sql statement: alter database datafile 7 online
Starting recover at 27-MAY-21
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 7 is already on disk as file /oracle/archives/1_7_1073680050.dbf
archived log for thread 1 with sequence 8 is already on disk as file /oracle/archives/1_8_1073680050.dbf
archived log for thread 1 with sequence 9 is already on disk as file /oracle/archives/1_9_1073680050.dbf
archived log for thread 1 with sequence 10 is already on disk as file /oracle/archives/1_10_1073680050.dbf
archived log file name=/oracle/archives/1_7_1073680050.dbf thread=1 sequence=7
archived log file name=/oracle/archives/1_8_1073680050.dbf thread=1 sequence=8
archived log file name=/oracle/archives/1_9_1073680050.dbf thread=1 sequence=9
archived log file name=/oracle/archives/1_10_1073680050.dbf thread=1 sequence=10
media recovery complete, elapsed time: 00:00:01
Finished recover at 27-MAY-21
sql statement: alter database open read only
Oracle instance shut down
Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/PITR/ASWAN/datafile/o1_mf_sysaux_jc0drdvs_.dbf deleted
auxiliary instance file /oracle/PITR/ASWAN/controlfile/o1_mf_jc0dr6bo_.ctl deleted
Finished recover at 27-MAY-21
Abrindo o PDB em RESETLOGS:
SQL> SELECT NAME,OPEN_MODE FROM V$PDBS;
NAME
--------------------------------------------------------------------------------
OPEN_MODE
----------
PDB$SEED
READ ONLY
HIPOFISE1
MOUNTED
SQL> ALTER PLUGGABLE DATABASE HIPOFISE1 OPEN RESETLOGS;
Pluggable database altered.
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
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.