Performing PITR on a Tablespace in a PDB

Podemos ter um cenário de necessidade de recuperação mais controlada, ou seja, que não precisemos recuperar um PDB todo, mas sim alguma(s) tablespace(s) dele. Esse recurso é ótimo, pois preserva a operação nas demais tablespaces do PDB, enquanto o processo de recuperação é executado. Mas o ônus disso é precisarmos de mais disco no ambiente, uma vez que uma instância auxiliar é criada pelo RMAN para o recover tablespace (exigindo mais espaço e tempo se comparado com o restore/recover do PDB completo).

Para iniciar, vamos identificar qual é a tablespace afetada pela tabela que usaremos como teste neste artigo:

[oracle@oel7 ~]$ sqlplus / as sysdba
 
SQL*Plus: Release 19.0.0.0.0 - Production on Thu May 27 05:34:42 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> SELECT TABLESPACE_NAME FROM DBA_TABLES WHERE TABLE_NAME='TESTE1';
 
TABLESPACE_NAME
------------------------------
USERS

Confirmando se a tablespace USERS é a default do nosso PDB. Nesse caso, precisaremos criar uma tablespace paralela para que exerça essa função durante a recuperação da USERS:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'DEFAULT_PERMANENT_TABLESPACE';
 
PROPERTY_VALUE
--------------------------------------------------------------------------------
USERS
 
SQL> SELECT STATUS FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='USERS';
 
STATUS
---------
ONLINE
 
SQL> CREATE TABLESPACE BSS;
 
Tablespace created.
 
SQL> ALTER DATABASE DEFAULT TABLESPACE BSS;
 
Database altered.

Realizando um backup FULL do CDB$ROOT e seus respectivos PDBs:

[oracle@oel7 ~]$ rman target /
 
Recovery Manager: Release 19.0.0.0.0 - Production on Thu May 27 05:41:44 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 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=448 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
input archived log thread=1 sequence=11 RECID=6 STAMP=1073626917
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/ASWN/backupset/2021_05_27/o1_mf_annnn_TAG20210527T054158_jbyptpk3_.bkp tag=TAG20210527T054158 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:17
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/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 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypv7jt_.bkp tag=TAG20210527T054215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15
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
input datafile file number=00013 name=/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_bss_jbypnbl0_.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/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypxlgh_.bkp tag=TAG20210527T054215 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/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 27-MAY-21
channel ORA_DISK_1: finished piece 1 at 27-MAY-21
piece handle=/oracle/fra/ASWN/C337AF22DF9E22E0E0536C00A8C0D589/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypycl2_.bkp tag=TAG20210527T054215 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
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=12 RECID=7 STAMP=1073627070
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/ASWN/backupset/2021_05_27/o1_mf_annnn_TAG20210527T054430_jbypzh1o_.bkp tag=TAG20210527T054430 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/ASWN/autobackup/2021_05_27/o1_mf_s_1073627072_jbypzk2r_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 27-MAY-21

Observando o conteúdo de nossa tabela de teste para podermos comparar após a recuperação da tablespace:

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

Coletando o SCN atual do banco de dados:

SQL> SELECT CURRENT_SCN FROM V$DATABASE;
 
CURRENT_SCN
-----------
    2182658

Gerando alguns archives:

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

System altered.

SQL> /

System altered.

Deletando os registros da nossa tabela de testes:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> DELETE FROM BSS1.TESTE1;
 
3 rows deleted.
 
SQL> COMMIT;
 
Commit complete.
 
SQL> SELECT * FROM BSS1.TESTE1;
 
no rows selected

Para nos prepararmos para a recuperação, vamos colocar a tablespace em questão no modo Offline:

SQL> ALTER TABLESPACE USERS OFFLINE IMMEDIATE;
 
Tablespace altered.

Como uma instância auxiliar será criada automaticamente pelo RMAN, vou disponibilizar um diretório específico para que possa ser usado no processo:

[oracle@oel7 BACKUP]$ pwd
/oracle/BACKUP

Agora podemos disparar a recuperação da tablespace conforme comando abaixo no RMAN:

[oracle@oel7 BACKUP]$ rman target /
 
Recovery Manager: Release 19.0.0.0.0 - Production on Thu May 27 05:51:33 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> RECOVER TABLESPACE HIPOFISE1:USERS UNTIL SCN 2182658 AUXILIARY DESTINATION='/oracle/BACKUP';
 
Starting recover at 27-MAY-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=29 device type=DISK
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 HIPOFISE1:SYSTEM
Tablespace UNDOTBS1
Tablespace HIPOFISE1:UNDOTBS1
 
Creating automatic instance, with SID='jcoy'
 
initialization parameters used for automatic instance:
db_name=ASWN
db_unique_name=jcoy_pitr_HIPOFISE1_ASWN
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=1024M
processes=200
db_create_file_dest=/oracle/BACKUP
log_archive_dest_1='location=/oracle/BACKUP'
enable_pluggable_database=true
_clone_one_pdb_recovery=true
#No auxiliary parameter file used
 
 
starting up automatic instance ASWN
 
Oracle instance started
 
Total System Global Area    1073738288 bytes
 
Fixed Size                     9142832 bytes
Variable Size                276824064 bytes
Database Buffers             784334848 bytes
Redo Buffers                   3436544 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully
 
contents of Memory Script:
{
# set requested point in time
set until  scn 2182658;
# restore the controlfile
restore clone controlfile;
 
# mount the controlfile
sql clone 'alter database mount clone database';
 
# archive current online log
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
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=38 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/ASWN/autobackup/2021_05_27/o1_mf_s_1073627072_jbypzk2r_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fra/ASWN/autobackup/2021_05_27/o1_mf_s_1073627072_jbypzk2r_.bkp tag=TAG20210527T054432
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/BACKUP/ASWN/controlfile/o1_mf_jbyqfg13_.ctl
Finished restore at 27-MAY-21
 
sql statement: alter database mount clone database
 
sql statement: alter system archive log current
 
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
 
contents of Memory Script:
{
# set requested point in time
set until  scn 2182658;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile  1 to new;
set newname for clone datafile  9 to new;
set newname for clone datafile  4 to new;
set newname for clone datafile  11 to new;
set newname for clone datafile  3 to new;
set newname for clone datafile  10 to new;
set newname for clone tempfile  1 to new;
set newname for clone tempfile  3 to new;
set newname for datafile  12 to
 "/oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_users_jbw042o2_.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile  1, 9, 4, 11, 3, 10, 12;
 
switch clone datafile all;
}
executing Memory Script
 
executing command: SET until clause
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
executing command: SET NEWNAME
 
renamed tempfile 1 to /oracle/BACKUP/ASWN/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 3 to /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_temp_%u_.tmp in control file
 
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/BACKUP/ASWN/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/BACKUP/ASWN/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/BACKUP/ASWN/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/fra/ASWN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypv7jt_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fra/ASWN/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypv7jt_.bkp tag=TAG20210527T054215
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55
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 00009 to /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00011 to /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00010 to /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00012 to /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_users_jbw042o2_.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/fra/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypxlgh_.bkp
channel ORA_AUX_DISK_1: piece handle=/oracle/fra/ASWN/C3380A6B7D7F3074E0536C00A8C08618/backupset/2021_05_27/o1_mf_nnndf_TAG20210527T054215_jbypxlgh_.bkp tag=TAG20210527T054215
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 27-MAY-21
 
datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/datafile/o1_mf_system_jbyqfn9v_.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=11 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_system_jbyqhccb_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/datafile/o1_mf_undotbs1_jbyqfncn_.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=13 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_undotbs1_jbyqhccb_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/datafile/o1_mf_sysaux_jbyqfncm_.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=15 STAMP=1073627604 file name=/oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_sysaux_jbyqhc93_.dbf
 
contents of Memory Script:
{
# set requested point in time
set until  scn 2182658;
# online the datafiles restored or switched
sql clone "alter database datafile  1 online";
sql clone 'HIPOFISE1' "alter database datafile
 9 online";
sql clone "alter database datafile  4 online";
sql clone 'HIPOFISE1' "alter database datafile
 11 online";
sql clone "alter database datafile  3 online";
sql clone 'HIPOFISE1' "alter database datafile
 10 online";
sql clone 'HIPOFISE1' "alter database datafile
 12 online";
# recover and open resetlogs
recover clone database tablespace  "HIPOFISE1":"USERS", "SYSTEM", "HIPOFISE1":"SYSTEM", "UNDOTBS1", "HIPOFISE1":"UNDOTBS1", "SYSAUX", "HIPOFISE1":"SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
 
executing command: SET until clause
 
sql statement: alter database datafile  1 online
 
sql statement: alter database datafile  9 online
 
sql statement: alter database datafile  4 online
 
sql statement: alter database datafile  11 online
 
sql statement: alter database datafile  3 online
 
sql statement: alter database datafile  10 online
 
sql statement: alter database datafile  12 online
 
Starting recover at 27-MAY-21
using channel ORA_AUX_DISK_1
 
starting media recovery
 
archived log for thread 1 with sequence 12 is already on disk as file /oracle/archives/1_12_1073536073.dbf
archived log for thread 1 with sequence 13 is already on disk as file /oracle/archives/1_13_1073536073.dbf
archived log file name=/oracle/archives/1_12_1073536073.dbf thread=1 sequence=12
archived log file name=/oracle/archives/1_13_1073536073.dbf thread=1 sequence=13
media recovery complete, elapsed time: 00:00:01
Finished recover at 27-MAY-21
 
database opened
 
contents of Memory Script:
{
sql clone 'alter pluggable database  HIPOFISE1 open';
}
executing Memory Script
 
sql statement: alter pluggable database  HIPOFISE1 open
 
contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'HIPOFISE1' 'alter tablespace
 USERS read only';
# create directory for datapump import
sql 'HIPOFISE1' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/oracle/BACKUP''";
# create directory for datapump export
sql clone 'HIPOFISE1' "create or replace directory
TSPITR_DIROBJ_DPDIR as ''
/oracle/BACKUP''";
}
executing Memory Script
 
sql statement: alter tablespace  USERS read only
 
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/BACKUP''
 
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/oracle/BACKUP''
 
Performing export of metadata...
   EXPDP> Starting "SYS"."TSPITR_EXP_jcoy_hAvn":
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   EXPDP> Master table "SYS"."TSPITR_EXP_jcoy_hAvn" successfully loaded/unloaded
   EXPDP> ******************************************************************************
   EXPDP> Dump file set for SYS.TSPITR_EXP_jcoy_hAvn is:
   EXPDP>   /oracle/BACKUP/tspitr_jcoy_47509.dmp
   EXPDP> ******************************************************************************
   EXPDP> Datafiles required for transportable tablespace USERS:
   EXPDP>   /oracle/dados/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_users_jbw042o2_.dbf
   EXPDP> Job "SYS"."TSPITR_EXP_jcoy_hAvn" successfully completed at Thu May 27 05:54:26 2021 elapsed 0 00:00:24
Export completed
 
 
contents of Memory Script:
{
# shutdown clone before import
shutdown clone abort
# drop target tablespaces before importing them back
sql 'HIPOFISE1' 'drop tablespace
 USERS including contents keep datafiles cascade constraints';
}
executing Memory Script
 
Oracle instance shut down
 
sql statement: drop tablespace  USERS including contents keep datafiles cascade constraints
 
Performing import of metadata...
   IMPDP> Master table "SYS"."TSPITR_IMP_jcoy_Eaov" successfully loaded/unloaded
   IMPDP> Starting "SYS"."TSPITR_IMP_jcoy_Eaov":
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/TABLE_STATISTICS
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/STATISTICS/MARKER
   IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
   IMPDP> Job "SYS"."TSPITR_IMP_jcoy_Eaov" successfully completed at Thu May 27 05:55:01 2021 elapsed 0 00:00:23
Import completed
 
 
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'HIPOFISE1' 'alter tablespace
 USERS read write';
sql 'HIPOFISE1' 'alter tablespace
 USERS offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
 
sql statement: alter tablespace  USERS read write
 
sql statement: alter tablespace  USERS offline
 
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
 
Removing automatic instance
Automatic instance removed
auxiliary instance file /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_temp_jbyqjtbn_.tmp deleted
auxiliary instance file /oracle/BACKUP/ASWN/datafile/o1_mf_temp_jbyqjpwb_.tmp deleted
auxiliary instance file /oracle/BACKUP/ASWN/onlinelog/o1_mf_3_jbyqjh1l_.log deleted
auxiliary instance file /oracle/BACKUP/ASWN/onlinelog/o1_mf_2_jbyqj78m_.log deleted
auxiliary instance file /oracle/BACKUP/ASWN/onlinelog/o1_mf_1_jbyqj766_.log deleted
auxiliary instance file /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_sysaux_jbyqhc93_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/datafile/o1_mf_sysaux_jbyqfncm_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_undotbs1_jbyqhccb_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/datafile/o1_mf_undotbs1_jbyqfncn_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/C3380A6B7D7F3074E0536C00A8C08618/datafile/o1_mf_system_jbyqhccb_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/datafile/o1_mf_system_jbyqfn9v_.dbf deleted
auxiliary instance file /oracle/BACKUP/ASWN/controlfile/o1_mf_jbyqfg13_.ctl deleted
auxiliary instance file tspitr_jcoy_47509.dmp deleted
Finished recover at 27-MAY-21

De forma resumida, o que conseguimos abstrair do Log de recuperação: a instância auxiliar é criada automaticamente, e percebemos que a sua definição de memória é baseada na instância original. Desse modo, devemos garantir que nossa máquina possuirá o recurso de memória necessário. Depois disso, o control file é recuperado, o banco montado, e é iniciado o restore dos datafiles para o diretório temporário que definimos. O recover dos datafiles é realizado e o banco é aberto em noresetlogs. Um directory é criado para o mesmo diretório que definimos, e um expdp da tablespace recuperada é disparado. Por fim, o banco e instância auxiliares são removidos e é realizado um IMPDP da tablespace no ambiente original.

Agora podemos colocar a tablespace USERS recuperada em status de online:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> SELECT STATUS FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='USERS';
 
STATUS
---------
OFFLINE
 
SQL> ALTER TABLESPACE USERS ONLINE;
 
Tablespace altered.

Confirmando que nossa tabela de teste está com o conteúdo desejado:

SQL> SELECT * FROM BSS1.TESTE1;
 
DESCRICAO
--------------------
PITR PDB 1
PITR PDB 2
PITR PDB 3

Em ambientes corporativos, é indicado realizar um backup completo do ambiente após esse procedimento.

Tornando a tablespace USERS novamente a default do nosso PDB, e caso a tablespace criada não possua segmentos, podemos removê-la. Caso contrário, basta fazermos o move dos segmentos para a tablespace USERS:

SQL> ALTER SESSION SET CONTAINER=HIPOFISE1;
 
Session altered.
 
SQL> SELECT COUNT(*) FROM DBA_SEGMENTS WHERE TABLESPACE_NAME='BSS';
 
  COUNT(*)
----------
         0
 
SQL> ALTER DATABASE DEFAULT TABLESPACE USERS;
 
Database altered.
 
SQL> DROP TABLESPACE BSS INCLUDING CONTENTS AND DATAFILES;
 
Tablespace dropped.

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.