Skip to content

Commit d5e06af

Browse files
Merge pull request #308 from oracle-devrel/sdu-branch4
Sdu branch4
2 parents 3b4e586 + 28acfea commit d5e06af

24 files changed

+755
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Workshops
2+
3+
In this section you'll detailed material about the workshops we propose to either customers or internally.
4+
5+
# License
6+
7+
Copyright (c) 2023 Oracle and/or its affiliates.
8+
9+
Licensed under the Universal Permissive License (UPL), Version 1.0.
10+
11+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/folder-structure/LICENSE) for more details.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Create a new PDB in the container database (CDB)
2+
3+
sqlplus / as sysdba
4+
create pluggable database PDB1 admin user pdbadmin identified by "Oracle_4U";
5+
6+
show pdbs
7+
8+
alter pluggable database PDB1 open read write;
9+
10+
show pdbs
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Unplug a PDB from its CDB
2+
3+
--- First we connect to the CDB.
4+
5+
sqlplus / as sysdba
6+
7+
show pdbs
8+
9+
alter pluggable database PDB1 close immediate;
10+
alter pluggable database PDB1 unplug into '/home/oracle/PDB1.xml';
11+
drop pluggable database PDB1 keep datafiles;
12+
13+
show pdbs
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Check the PDB compatibility before plugging it in the target CDB
2+
3+
sqlplus / as sysdba
4+
set serveroutput on
5+
DECLARE
6+
compatible BOOLEAN := FALSE;
7+
BEGIN
8+
compatible := DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
9+
pdb_descr_file => '/home/oracle/PDB1.xml');
10+
if compatible then
11+
DBMS_OUTPUT.PUT_LINE('Is pluggable PDB1.xml compatible? YES');
12+
else
13+
DBMS_OUTPUT.PUT_LINE('Is pluggable PDB1.xml compatible? NO');
14+
end if;
15+
END;
16+
/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Plug a PDB by cloning from an unplugged PDB (as clone method)
2+
3+
sqlplus / as sysdba
4+
5+
--- Create a clone of PDB1 using the manifest file generated during the unplug command (copy the original datafiles)
6+
create pluggable database PDB1_clone as clone using '/home/oracle/PDB1.xml';
7+
8+
-- Plug the unplugged DB with nocopy method (reuse the datafiles)
9+
create pluggable database PDB1_nocopy using '/home/oracle/PDB1.xml' NOCOPY TEMPFILE REUSE;
10+
11+
show pdbs
12+
13+
alter pluggable database PDB1_nocopy open read write;
14+
alter pluggable database PDB1_CLONE open read write;
15+
16+
show pdbs
17+
18+
-- Now retrieve the datafiles names of PDB1_nocopy
19+
alter session set container = PDB1_nocopy;
20+
21+
--- This query retrieves the PDB's datafile names
22+
select file_name from dba_data_files;
23+
24+
--- Please write down these datafile names, as we will use them later on during the backup/restore lab.
25+
26+
--- Note that PDB GUID is used in the path to the datafiles
27+
select GUID from v$pdbs;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Create a new PDB from an existing PDB
2+
3+
sqlplus / as sysdba
4+
create pluggable database PDB1 from PDB1_nocopy;
5+
alter pluggable database PDB1 open read write;
6+
show pdbs
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- Create a refreshable PDB from an existing PDB
2+
3+
-- First we connect to the CDB$ROOT, and create a common user
4+
sqlplus / as sysdba
5+
6+
--- Note the C## prefix in the username (common user), and the "container=ALL" clause in the grant commands
7+
create user C##_ADMIN_PDB identified by "Oracle_4U" container=ALL;
8+
grant CREATE PLUGGABLE DATABASE to C##_ADMIN_PDB container=ALL;
9+
grant create session to C##_ADMIN_PDB container=ALL;
10+
11+
-- Then we create a database link connected to that user. In our case, the database link is a loopback, since we only have one CDB
12+
create database link DBL_ORCLCDB connect to C##_ADMIN_PDB identified by "Oracle_4U" using 'myoracledb:1521/ORCLCDB';
13+
14+
--- Check that the database link is working fine
15+
select * from dual@DBL_ORCLCDB;
16+
17+
create pluggable database PDB1_REFRESH from PDB1@DBL_ORCLCDB refresh mode manual;
18+
19+
--- A refreshable PDB can only be opened in read only mode. If you try to open it in read write, it will be opened in read only anyway.
20+
21+
alter pluggable database PDB1_REFRESH open read only;
22+
23+
show pdbs
24+
25+
-- Create some new data in the source PDB
26+
--- Connect to PDB1 and create a local user with a table
27+
28+
sqlplus system/Oracle_4U@myoracledb:1521/PDB1
29+
30+
create tablespace USERS datafile size 50M;
31+
create user TEST_REFRESH identified by "Oracle_4U" temporary tablespace TEMP default tablespace USERS;
32+
grant connect, resource to TEST_REFRESH;
33+
alter user TEST_REFRESH quota unlimited on USERS;
34+
35+
--- Connect to TEST_REFRESH schema and create a new table
36+
sqlplus TEST_REFRESH/Oracle_4U@myoracledb:1521/PDB1
37+
create table TT (c1 number);
38+
insert into TT values (999);
39+
commit;
40+
41+
--- Connect to PDB1_REFRESH PDB as system, and check
42+
sqlplus system/Oracle_4U@myoracledb:1521/PDB1_REFRESH
43+
select username from dba_users where username = 'TEST_REFRESH';
44+
-- We need to refresh this PDB
45+
46+
-- Then refresh the refreshable clone, and check the new data is there
47+
sqlplus / as sysdba
48+
alter pluggable database PDB1_REFRESH close immediate;
49+
alter pluggable database PDB1_REFRESH refresh;
50+
show pdbs
51+
52+
alter pluggable database PDB1_REFRESH open read only;
53+
54+
sqlplus TEST_REFRESH/Oracle_4U@myoracledb:1521/PDB1_REFRESH
55+
select * from tt;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- Create a snap clone on the refreshable PDB
2+
3+
-- On the PDB1_REFRESH PDB, used as a TEST MASTER, we create two sparse clones
4+
-- Sparse techonoly
5+
-- Sparse datafiles clones are thin clones, that are sustained by the copy on write technology of the storage
6+
-- Sparse clones creation is extremely fast, as pointers to the TEST MASTER are created, instead of physically cloning the TEST MASTER datafiles
7+
8+
sqlplus / as sysdba
9+
show pdbs
10+
11+
create pluggable database PDB1_SNAP1 from PDB1_REFRESH snapshot copy;
12+
create pluggable database PDB1_SNAP2 from PDB1_REFRESH snapshot copy;
13+
alter pluggable database PDB1_SNAP1 open;
14+
alter pluggable database PDB1_SNAP2 open;
15+
16+
show pdbs
17+
18+
-- Unlike their TEST MASTER, the snapshot copies are opened in read write, allowing users to create their own data.
19+
-- Connect to PDB1_SNAP1, and run:
20+
21+
sqlplus TEST_REFRESH/Oracle_4U@myoracledb:1521/PDB1_SNAP1
22+
select * from tt;
23+
insert into tt values (1000);
24+
commit;
25+
select * from tt;
26+
27+
-- Now connect to PDB1_SNAP2 and check the TT table:
28+
sqlplus TEST_REFRESH/Oracle_4U@myoracledb:1521/PDB1_SNAP2
29+
select * from tt;
30+
31+
-- Only the data from the TEST MASTER is visible, not the data created in PDB1_SNAP1
32+
delete tt;
33+
insert into tt values (1001);
34+
commit;
35+
select * from tt;
36+
37+
-- We can even modify (delete) the original data, without affecting the TEST MASTER: connect to the TEST MASTER and check:
38+
sqlplus TEST_REFRESH/Oracle_4U@myoracledb:1521/PDB1_REFRESH
39+
select * from tt;
40+
41+
-- This illustrates the "copy on write" functionality
42+
-- If we refresh the TEST MASTER, we will first drop the snapshot copies, and re-create them after the TEST MASTER refresh.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- PDB Backup and restore
2+
3+
rman target=/
4+
5+
BACKUP PLUGGABLE DATABASE PDB1_NOCOPY;
6+
exit
7+
8+
--- Remove a datafile from the operating system: change the file name by your file name !!!
9+
--- You need to use the file name for tablespace SYSTEM, as returned previously in page 6
10+
11+
rm /opt/oracle/oradata/ORCLCDB/CDADC32D998ECE2AE053E414010AA42A/datafile/o1_mf_sys tem_jotz78l7_.dbf
12+
13+
--- Connect to the PDB
14+
sqlplus system/Oracle_4U@myoracledb:1521/PDB1_NOCOPY
15+
16+
-- This fails !!!
17+
18+
ORA-27041: unable to open
19+
Linux-x86_64 Error: 2: No
20+
Additional information: 3
21+
ORA-00604: error occurred
22+
ORA-01116: error in opening database file 19
23+
ORA-01110: data file 19: '/opt/oracle/oradata/ORCLCDB/CDADC32D998ECE2AE053E414010AA42A/datafile/o1_mf_sy s
24+
tem_jotz78l7_.dbf'
25+
ORA-27041: unable to open file
26+
Linux-x86_64 Error: 2: No such file or directory Additional information: 3
27+
28+
--- Ensure datafile ID (19) matches with your environment
29+
30+
rman target=/
31+
32+
RUN {
33+
alter pluggable database PDB1_NOCOPY close immediate;
34+
RESTORE datafile 19;
35+
RECOVER PLUGGABLE DATABASE PDB1_NOCOPY;
36+
ALTER PLUGGABLE DATABASE PDB1_NOCOPY open;
37+
}
38+
39+
--- Check that the PDB is now sucessufully opened and accessible
40+
sqlplus / as sysdba
41+
show pdbs
42+
43+
sqlplus system/Oracle_4U@myoracledb:1521/PDB1_NOCOPY
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- PDB Flashback
2+
3+
-- Connect to ORCLPDB1 PDB, and create a local user
4+
sqlplus system/"Oracle_4U"@myoracledb:1521/ORCLPDB1
5+
6+
create user TEST_FLASHBACK identified by "Oracle_4U" default tablespace USERS temporary tablespace TEMP;
7+
grant connect, resource to TEST_FLASHBACK;
8+
alter user TEST_FLASHBACK quota unlimited on USERS;
9+
exit
10+
11+
-- Connect to TEST_FASHBACK schema and create a table
12+
sqlplus TEST_FLASHBACK/"Oracle_4U"@myoracledb:1521/ORCLPDB1
13+
14+
create table tt (c1 number);
15+
insert into tt values (1);
16+
insert into tt values (2);
17+
commit;
18+
exit
19+
20+
-- Now we create a restore point
21+
sqlplus sys/Oracle_4U@myoracledb:1521/ORCLPDB1 as sysdba
22+
create restore point RP_1 guarantee flashback database;
23+
exit
24+
25+
-- Now connect to TEST_FLASHBACK schema and drop the table
26+
sqlplus TEST_FLASHBACK/"Oracle_4U"@myoracledb:1521/ORCLPDB1
27+
drop table tt;
28+
exit
29+
30+
-- Now connect to the CDB and flashback the PDB to the restore point
31+
sqlplus / as sysdba
32+
alter pluggable database ORCLPDB1 close immediate;
33+
flashback pluggable database ORCLPDB1 to restore point RP_1;
34+
35+
show pdbs
36+
37+
alter pluggable database ORCLPDB1 open resetlogs;
38+
39+
show pdbs
40+
41+
-- Now connect to TEST_FLASHBACK schema and check the table is back
42+
sqlplus TEST_FLASHBACK/"Oracle_4U"@myoracledb:1521/ORCLPDB1
43+
select * from tt;

0 commit comments

Comments
 (0)