In a multitenant environment, we basically use 2 terms to indicate the container mode Dedicated Container & Shared Container.
Dedicated Container: When there is only one PDB resides under a root container except PDB$SEED then that type of container we called as dedicated container.
Shared Container: When there are multiple PDB resides under a root container then that type of container we called as shared container.
Sometimes we
receive a request to flashback a PDB in a shared container environment and in
that case we’ve to flashback only that particular PDB not the entire CDB,
flashback the entire CDB in a shared container mode only to flashback one PDB
will create lot of issues and outage as well, so prior to flashback a PDB we
must have to validate whether the container is a Dedicated or shared one.
Steps To Flashback PDB In a Shared Container
Step 1st: Check if local undo is enabled or not
One of the mandatory and important condition to flashback a PDB is to check whether local undo is enabled or not, if local undo is not enabled then we can’t flashback a PDB.
NOTE: Till
12.1 since local undo feature was not available. So, we were not able to flashback
a PDB under the same container, however 12.2 onward oracle has provided the feature of local undo and now
we can flashback a PDB as well.
SQL> show
pdbs
CON_ID|CON_NAME |OPEN
MODE |RESTRICTED
----------|--------------------------------------|----------|----------
2|PDB$SEED |READ ONLY |NO
3|PDB1 |READ
WRITE|NO Ã
Target PDB
4|PDB2 |READ
WRITE|NO
SQL> select
con_id,property_name,property_value from cdb_properties where
property_name='LOCAL_UNDO_ENABLED';
CON_ID|PROPERTY_NAME
|PROPERTY_VALUE
------|------------------------------|--------------------
1|LOCAL_UNDO_ENABLED
|TRUE
3|LOCAL_UNDO_ENABLED
|TRUE
4|LOCAL_UNDO_ENABLED
|TRUE
Step 2nd: Create
user and insert some data only for testing
NOTE: In a real time, environment, step 2 is not necessary because all the time application team approaches DBA team to flashback the database.
SQL> alter
session set container=PDB1;
Session altered.
SQL> conn
test@PDB1/*******
Connected.
SQL> show user
USER is
"TEST"
SQL> select
count(*) from user_objects;
COUNT(*)
----------
0
SQL> alter
session set container=PDB1;
SQL> show
con_name
CON_NAME
------------------------------
PDB1
SQL> create restore point PDB_FLSHBK_TEST guarantee flashback
database;
Restore point created.
SQL> set lines
300 colsep '|'
SQL> col name for
a30
SQL> col time for
a40
SQL> col
preserved for a15
SQL> col
guarantee_flashback_database for a30
SQL> col con_id
for 999999
SQL> select
con_id,name,time,preserved,guarantee_flashback_Database from v$restore_point;
CON_ID|NAME |TIME |PRESERVED |GUARANTEE_FLASHBACK_DATABASE
-------|------------------------------|----------------------------------------|---------------|--------------------
3|PDB_FLSHBK_TEST |01-JAN-24 04.22.23.000000000 PM
|YES |YES
SQL> set verify
off
SQL> insert into
test values (&order_id,'&order_name','&order_date');
Enter value for
order_id: 100
Enter value for
order_name: SHOES
Enter value for
order_date: 12-DEC-2022
1 row created.
SQL> /
Enter value for
order_id: 200
Enter value for
order_name: SHIRT
Enter value for
order_date: 14-MAY-2011
1 row created.
SQL> commit;
Commit complete.
SQL> select
count(*) from user_objects;
COUNT(*)
----------
1
Step 3rd: close
the PDB to perform flashback
NOTE: By
default, the closing state of PDB is mount
SQL> alter pluggable database PDB1 close immediate;
Pluggable database altered.
In Case Of RAC please use below command to close
PDB across cluster
SQL> alter pluggable database PDB1 close immediate instances=all;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
----------
------------------------------ ---------- ----------
2
PDB$SEED READ ONLY
NO
3
PDB1 MOUNTED
4
PDB2 READ WRITE NO
Step 4th: Flashback
the PDB
SQL> flashback pluggable database PDB1 to restore point
PDB_FLSHBK_TEST;
Flashback complete.
NOTE: We can also flashback pluggable database using the restore point created at root container level on the contrary we can't flashback the CDB/root container using the restore point created at PDB level.
PDB Flashback info in alter log
flashback pluggable
database PDB1 to restore point PDB_FLSHBK_TEST
2024-01-01T16:35:01.765892+05:30
Flashback Restore
Start
Restore Flashback
Pluggable Database PDB1 (3) until change 2490725
Flashback Restore
Complete
Flashback Media
Recovery Start
Incomplete Recovery
applied until change 2495767 time 01/01/2024 16:22:23
Flashback Media
Recovery Complete
Flashback Pluggable Database PDB1 (3) recovered until change
2495767
Completed: flashback pluggable database PDB1 to restore point
PDB_FLSHBK_TEST
Step 5th: Start
PDB with resetlogs option
SQL> alter pluggable database PDB1 open resetlogs;
Pluggable database altered.
NOTE: If PDB
also has a standby database then when we bounce the CDB and start the MRP again
then Standby PDB will also flashback automatically
Step 6th: Start
all the required services and check remote connectivity as well
Step 7th: Release
the PDB to application team , so that they can validate their data
SQL> alter
session set container=PDB1;
Session altered.
SQL> show
con_name
CON_NAME
------------------------------
PDB1
SQL> conn
test@PDB1/******
Connected.
SQL> show user
USER is
"TEST"
SQL> select
count(*) from user_objects;
COUNT(*)
----------
0
Step 8th: Remove
the blackout from the database.