Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
--WHERE AM I CONNECTED?
SQL> show con_name
CON_NAME
———
PDB1
— 1 pdb
alter pluggable database pdb_name save state;
— All pdbs
alter pluggable database all save state;
— All except
alter pluggable database all except pdb1, pdb2 save state;
############################################################################
### 12c How to plugin a non-CDB database to a Container Database (CDB) ###
############################################################################
BEGIN
DBMS_PDB.DESCRIBE(
pdb_descr_file => '/u01/scripts/rac.xml');
END;
/
DECLARE
compatible CONSTANT VARCHAR2(3) :=
CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/u01/scripts/rac.xml',
pdb_name => 'RAC')
WHEN TRUE THEN 'YES'
ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/
CREATE PLUGGABLE DATABASE RAC using '/u01/scripts/rac.xml' nocopy tempfile reuse;
show con_name
show con_name
@/u01/products/rdbms_12102/rdbms/admin/noncdb_to_pdb.sql
#####################################
### Add and Start New PDB service ###
#####################################
./srvctl add service -db cdb12c -service pdb_srv -preferred cdb12c1 -pdb RAC
./srvctl start service -db cdb12c -s pdb_srv
###################################################################################
#####################################
### Save state of PDB. By defualt the PDB's starup in mounted state. Use the
following cmd to persere the open state.###
###################################################################################
#####################################
##############################
### Connect to PDB Service ###
##############################
sqlplus system/racattack@collabn1:1521/ucpdb
Schema/Password@HOST:Port/Service_Name
################################################
### Open all PDB's that are on mounted mode ###
################################################
##################
### Switch CDB ###
##################
###############################
### Display active services ###
###############################
select name, con_id from v$active_services order by 1;
NAME CON_ID
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
SYS$USERS 1
cdb12c 1
cdb12cXDB 1
pdb_srv 3
rac 3
ucpdb 4
##########################
### Display Containers ###
##########################
###########################
### Display PDB Status ###
###########################
PDB_NAME STATUS
-------------------------------------------------- ---------
PDB$SEED NORMAL
RAC NORMAL
UCPDB NORMAL
###############################
### Display Open_Mode of PDB###
###############################
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
RAC READ WRITE
UCPDB READ WRITE
#########################################################
### Display all datafile at the root container level ###
#########################################################
###########################################################
### Display all tablespaces at the root container level ###
###########################################################
TABLESPACE_NAME CON_ID
-------------------------------------------------- ----------
SYSTEM 1
USERS 1
SYSAUX 1
TEMP 1
UNDOTBS1 1
UNDOTBS2 1
SYSTEM 3
SYSAUX 3
UNDOTBS2 3
TEMP 3
USERS 3
UNDOTBS1 3
SYSTEM 4
USERS 4
TEMP 4
SYSAUX 4
#########################################################
### Display all tempfiles at the root container level ###
#########################################################
set linesize 500
column FILE_NAME format a100
select file_name,con_id from cdb_temp_files order by con_id;
FILE_NAME
CON_ID
-----------------------------------------------------------------------------------
----------------- ----------
+DATA/CDB12C/TEMPFILE/temp.300.908285829
1
+DATA/CDB12C/F2CCC568CEF64318E043334EA8C05910/TEMPFILE/temp.307.908366901
3
+DATA/CDB12C/2FFB70F5EDFF486AE053334EA8C0FF4E/TEMPFILE/temp.310.908622149
4
##################################################
### Create common user while connected to root ###
##################################################
##################
### Drop PDB ###
##################
--Connect to container DB
$ export ORACLE_SID=cdb1
$ . oraenv
$ sqlplus / as sydba
CON_NAME
------------------------------
CDB$ROOT
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
JOHNPDB MOUNTED
TIGGER MOUNTED
--DROP PDB
SQL> drop pluggable database TIGGER including datafiles;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
JOHNPDB MOUNTED
#############
Overview
#############
Purpose
This tutorial covers the steps for using Oracle Recovery Manager (Oracle RMAN) to
perform a point-in-time recovery for a pluggable database (PDB).
Time to Complete
Approximately 30 minutes
Introduction
A user error or corruption removes needed data or introduces corrupted data. For
example, a user or DBA erroneously deletes or updates the contents of one or more
tables, drops database objects that are still needed during an update to an
application, or runs a large batch update that fails midway.
A database upgrade fails or an upgrade script goes awry.
A complete database recovery after a media failure cannot succeed because you do
not have all of the needed redo logs or incremental backups.
Here are the DBPITR requirements:
In this tutorial, you use Oracle RMAN to perform a point-in-time recovery on a PDB.
You make some erroneous data updates and then recover the database to the state it
was just before you performed the data updates.
Prerequisites
##################################
Preparing to Back up the CDB
##################################
Before backing up the database, you must create the backup directory and then put
the database in ARCHIVELOG mode.
cd /stage
Create a subdirectory called db_backup_files under /stage.
mkdir db_backup_files
Create a subdirectory called cdb1 under /stage/db_backup_files.
cd db_backup_files
mkdir cdb1
shutdown immediate
Start the database in mount mode.
startup mount
Turn on database archiving.
exit
############################
Backing Up the CDB
############################
Use Oracle RMAN to back up the database to the directory that was specified in the
previous section.
Set the NLS_DATE_FORMAT environment variable so that the date and time values
displayed by RMAN can be more easily read.
Make sure that ORACLE_HOME is set correctly.
Set ORACLE_SID to cdb1.
export NLS_DATE_FORMAT='DD-MM-YYYY HH:MI:SS'
rman target /
Set the Oracle RMAN backup device type and backup file location.
exit
###########################################
Performing Erroneous updates in the PDB
###########################################
In this section, you set up a tablespace, schema, and table in each PDBs. Next, you
insert some records in the tables. One of the batch inserts will be done "in
error."
###########################################
Performing Data Updates in PDB1
###########################################
begin
for i in 1.. 10000 loop
insert into dj.t1 values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
Make a note of the SCN and remain in SQL*Plus.
#################################################
Creating a Tablespace, Schema, and Table in PDB2
#################################################
create user jfv identified by jfv temporary tablespace temp default tablespace
jfv_pdb2;
#################################################
Performing Data Updates in PDB2
#################################################
Make a note of the current SCN, which is the point to which you will recover the
database.
select timestamp_to_scn(sysdate) from v$database;
begin
for i in 1.. 10000 loop
insert into jfv.t2 values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
Make a note of the SCN.
################################################
Recovering the PDB to a Certain Point in Time
################################################
To perform point-in-time recovery, you must first close the PDB. Use Oracle RMAN to
recover until the SCN before the erroneous data updates to the table in PDB2.
exit
Connect to Oracle RMAN.
rman target /
Perform point-in-time recovery in Oracle RMAN.
Make sure that you change the SET UNTIL SCN value to the SCN that you recorded in
step #1 in the "Performing Data Updates in PDB2" section. Also, set the AUXILIARY
DESTINATION value to a location with enough free space to hold a copy of the
database files.
run {
set until SCN = 2263440 ;
restore pluggable database pdb2;
recover pluggable database pdb2 auxiliary
destination='/stage/db_backup_files/cdb1';
alter pluggable database pdb2 open resetlogs;
}
Exit Oracle RMAN.
exit
################################################
Verifying Sucess of the Point-in-Time Recovery
################################################
If the point-in-time recovery was successful, you should see only one row in the
jfv.t2 table.
Check to see that the table contains only the one row inserted before the 10,000
record batch insert.
select * from t2;
exit
################################################
Resetting your environment
################################################
Perform the following steps to reset your environment prior to repeating the
activities covered in this OBE or starting another OBE.
. oraenv
connect / as sysdba
shutdown immediate
startup mount
exit
rm -rf /stage/db_backup_files
sqlplus system/racattack@dgprm:1521/TIGGER
###########################################
Performing Erroneous updates in the PDB
###########################################
In this section, you set up a tablespace, schema, and table in each PDBs. Next, you
insert some records in the tables. One of the batch inserts will be done "in
error."
###########################################
Performing Data Updates in PDB1
###########################################
begin
for i in 1.. 10000 loop
insert into dj.t1 values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
end loop;
commit;
end;
/
Make a note of the SCN and remain in SQL*Plus.