Вы находитесь на странице: 1из 39

ASSIGNMENT 1

======================
DATABASE LINK
=======================

1.Create 2 databases ORCL(remote) and TLSDMO(host)


2.The two database cannot connect without the TNSNAMES
3.Go to tns location and add an entry for TLSDMO and ORCL tns names
-o/s> $ORACLE_HOME/network/admin
-o/s> vi tnsnames.ora (add tnsnames for TLSDMO and ORCL)
4.Source env to point to the two databases
5.Make sure the two databases are up and running
sql>select instance_name,status from v$instance;

============================================================
NB. Make sure that the HR user password in the ORCL Database is set to HR
==============================================================

ON REMOTE DATABASE ORCL


6.Unlock hr account.
sql> alter user hr identified by hr1 account unlock;

7.check and make sure hr tables exist


sql> select table_name,owner from dba_tables where owner='HR';

ON HOST DATABASE TLSDMO


8.Drop user HR in the host datadase
sql> drop user scott cascade;
sql> Create user SCOTT identified by tiger;
sql> grant connect to SCOTT;

### To recreate a table that was droped


sql> create table hr.regions as select * from hr.regions@hr_link;

============================================================
Create a database link such that i am able to log in to TLSDMO and view the HR
schema in ORCL
===============================================================

9.Create database link


sql> create database link hr_link connect to hr identified by hr1 using 'RCAT';

10. Query to see data in ORCL using db link


sql> select * from hr.regions@play_link;
sql> select * from hr.locations@hr_link;
sql> select * from hr.employees@hr_link;

###Close a database link


sql> alter session close database link link_name;

###How to drop a database link


sql> drop database link hr_link;
sql> drop public database link link_name;
###what is needed###
TLSDMO ORCL
-lock to TLSDMO -unlock hr
-drop hr -check the tables in hr schema
-create user hr
-grant connect to hr
-create db link
-query to see data in ORCL using db link

Prerequisite (You should have created these databases already)

1) TLSDMO

2) ORCL

Notes

DATABASE LINKS

Assignment

Create a database link such that i am able to log in to TLSDMO and view the HR
schema in ORCL

NB. Make sure that the HR user password in the ORCL Database is set to HR

command

alter user HR identified by HR

Please verify that the link works


==================================

1)log into TLSDMO

2)select * from hr.REGIONS@

3)verify if the output is 107 rows selected.

SQL> select * from hr.REGIONS@HR_LINK;

REGION_ID REGION_NAME
---------- -------------------------
1 Europe
2 Americas
3 Asia
4 Middle East and Africa
ASSIGNMENT 2
=====================
SQL FUNDAMENTALS 1
======================

Done in TLSDMO
-source env to TLSDMO
-make sure lstener is up
==========================================================

1) Create 4 users in TLSDMO (DEMO, DEV, QAT, PROD)


===========================================================

-SQL> create user DEMO identified by demo1;


grant connect to DEMO;
grant resource to DEMO;

-SQL> create user DEV identified by dev1;


SQL> grant connect to DEV;
SQL> grant resource to DEV;

-SQL> create user QAT identified by qat1;


SQL> grant connect to QAT;
SQL> grant resource to QAT;

-SQL> create user PROD identified by prod1;


SQL> grant connect to PROD;
SQL> grant resource to PROD;

=================================================================================
2) copy all the tables in the HR schema to the above schemas
==================================================================================
SQL> create public database link db_link connect to hr identified by hr1 using
'ORCL';

SQL> conn DEV/dev1;

SQL> create table regions as select * from hr.regions@db_link;

SQL> create table countries as select * from hr.countries@db_link;

SQL> create table jobs as select * from hr.jobs@db_link;

SQL> create table employees as select * from hr.employees@db_link;

SQL> create table locations as select * from hr.locations@db_link;

SQL> create table departments as select * from hr.departments@db_link;

SQL> create table job_history as select * from hr.job_history@db_link;

=================================================================================
sqlplus PROD/prod1;
SQL> show user;
USER is "PROD"
SQL> create table regions as select * from hr.regions@db_link;
SQL> create table countries as select * from hr.countries@db_link;

SQL> create table jobs as select * from hr.jobs@db_link;

SQL> create table employees as select * from hr.employees@db_link;

SQL> create table locations as select * from hr.locations@db_link;

SQL> create table departments as select * from hr.departments@db_link;

SQL> create table job_history as select * from hr.job_history@db_link;

==================================================================================
sqlplus DEMO/demo1

SQL> show user


USER is "DEMO"
SQL> create table regions as select * from hr.regions@db_link;

SQL> create table countries as select * from hr.countries@db_link;

SQL> create table jobs as select * from hr.jobs@db_link;

SQL> create table employees as select * from hr.employees@db_link;

SQL> create table locations as select * from hr.locations@db_link;

SQL> create table departments as select * from hr.departments@db_link;

SQL> create table job_history as select * from hr.job_history@db_link;

==================================================================================
sqlplus QAT/qat1
SQL> show user
USER is "QAT"
SQL> create table regions as select * from hr.regions@db_link;

SQL> create table countries as select * from hr.countries@db_link;

SQL> create table jobs as select * from hr.jobs@db_link;

SQL> create table employees as select * from hr.employees@db_link;

SQL> create table locations as select * from hr.locations@db_link;

SQL> create table departments as select * from hr.departments@db_link;

SQL> create table job_history as select * from hr.job_history@db_link;

==================================================================================

3) Duplicate data in all tables in the schemas DEMO, DEV, QAT, PROD using the
"insert as select" functionality in TLSDMO
sqlplus QAT/qat1
SQL> show user
USER is "QAT"
SQL> insert into regions select * from hr.regions@db_link;

SQL> insert into job_history select * from hr.job_history@db_link;

SQL> insert into departments select * from hr.departments@db_link;

SQL> insert into locations select * from hr.locations@db_link;

SQL> insert into employees select * from hr.employees@db_link;

SQL> insert into countries select * from hr.countries@db_link;

SQL> commit;

===========================================================================

SQL> show user


USER is "DEMO"
SQL> insert into regions select * from hr.regions@db_link;

SQL> insert into job_history select * from hr.job_history@db_link;

SQL> insert into departments select * from hr.departments@db_link;

SQL> insert into locations select * from hr.locations@db_link;

SQL> insert into employees select * from hr.employees@db_link;

SQL> insert into countries select * from hr.countries@db_link;

SQL> commit;

==============================================================================
sqlplus PROD/prod1
SQL> show user
USER is "PROD"
SQL> insert into countries select * from hr.countries@db_link;

SQL> insert into jobs select * from hr.jobs@db_link;

SQL> insert into employees select * from hr.employees@db_link;

SQL> insert into locations select * from hr.locations@db_link;

SQL> insert into departments select * from hr.departments@db_link;

SQL> insert into job_history select * from hr.job_history@db_link;

SQL> insert into regions select * from hr.regions@db_link;

SQL> commit;

SQL> host
==============================================================================

sqlplus DEV/dev1
SQL> show user
USER is "DEV"
SQL> insert into regions select * from hr.regions@db_link;

SQL> insert into job_history select * from hr.job_history@db_link;

SQL> insert into departments select * from hr.departments@db_link;

SQL> insert into locations select * from hr.locations@db_link;

SQL> insert into employees select * from hr.employees@db_link;

SQL> insert into jobs select * from hr.jobs@db_link;

SQL> insert into countries select * from hr.countries@db_link;

SQL> commit;

Done in ORCL

Please note that this assignment should be done in the HR Schema of the ORCL
database. Note that this below practice has the answers so as to give you an
understanding of how the sql statements are represented based on the description
given

ASSIGNMENT3
====================
SQL FUNDAMENTALS 2
====================

Done in TLSDMO

==============================================================================
1) in TLSDMO update all last names in the employees table to BRONTECH in the DEMO,
DEV, QAT, PROD schemas
==============================================================================

SQL> sqlplus demo/demo1

SQL> update employees set last_name='BRONTECH';

SQL> commit;

SQL> host
==============================================================================
sqlplus dev/dev1
SQL> show user
USER is "DEV"
SQL> update employees set last_name='BRONTECH';

SQL> commit;
SQL> host
==============================================================================

SQL> sqlplus qat/qat1

SQL> update employees set last_name='BRONTECH';

SQL> commit;
SQL> host
==============================================================================
sqlplus prod/prod1
SQL> update employees set last_name='BRONTECH';

SQL> commit;

SQL> desc departments;

==============================================================================
2) in TLSDMO update DEPARTMENT_NAME Manufacturing and Construction to SCHOOL in the
DEPARTMENTS table in DEMO, DEV, QAT, PROD schemas
==============================================================================

sqlplus prod/prod1
SQL> update departments set department_name='SCHOOL' where department_id='180';

SQL> update departments set department_name='SCHOOL' where department_id='170';

SQL> commit;

SQL> host
==============================================================================
sqlplus dev/dev1
SQL> show user
USER is "DEV"

SQL> update departments set department_name='SCHOOL' where department_id='180';

SQL> update departments set department_name='SCHOOL' where department_id='170';

SQL> commit;

SQL> host
==============================================================================
sqlplus demo/demo1
SQL> show user
USER is "DEMO"
SQL> update departments set department_name='SCHOOL' where department_id='180';

SQL> update departments set department_name='SCHOOL' where department_id='170';

SQL> commit;

SQL> host
==============================================================================
sqlplus qat/qat1
SQL> show user
USER is "QAT"
SQL> update departments set department_name='SCHOOL' where department_id='170';

SQL> update departments set department_name='SCHOOL' where department_id='180';

SQL> commit;

Commit complete.

SQL> host
============================================================================
sqlplus / as sysdba
SQL> select * from demo.departments;(to check output)

Done in ORCL

Please note that this assignment should be done in the HR Schema of the ORCL
database

ASSIGNMENT4
===============
SQL FUNDAMENTALS 3
===================

Done in TLSDMO

==============================================================================
1) Create 4 tablespaces (DEMONSTATE, DEVELOPMENT, QATESTING, PRODUCTION)
==============================================================================

SQL> CREATE SMALLFILE TABLESPACE "DEMONSTATE" DATAFILE


'/oradata/TLSDMO/demonstate01.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K MAXSIZE
UNLIMITED , '/oradata/TLSDMO/demonstate02.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K
MAXSIZE UNLIMITED ,'/oradata/TLSDMO/demonstate03.dbf' SIZE 20M AUTOEXTEND ON NEXT
10K MAXSIZE UNLIMITED , '/oradata/TLSDMO/demonstate04.dbf' SIZE 20M AUTOEXTEND ON
NEXT 10K MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT
AUTO;

SQL> CREATE SMALLFILE TABLESPACE "DEVELOPMENT" DATAFILE


'/oradata/TLSDMO/development01.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K MAXSIZE
UNLIMITED , '/oradata/TLSDMO/development02.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K
MAXSIZE UNLIMITED ,'/oradata/TLSDMO/development03.dbf' SIZE 20M AUTOEXTEND ON NEXT
10K MAXSIZE UNLIMITED , '/oradata/TLSDMO/development04.dbf' SIZE 20M AUTOEXTEND ON
NEXT 10K MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT
AUTO;

SQL> CREATE SMALLFILE TABLESPACE "QATESTING" DATAFILE


'/oradata/TLSDMO/qatesting01.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K MAXSIZE UNLIMITED
, '/oradata/TLSDMO/qatesting02.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K MAXSIZE
UNLIMITED ,'/oradata/TLSDMO/qatesting03.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K
MAXSIZE UNLIMITED , '/oradata/TLSDMO/qatesting04.dbf' SIZE 20M AUTOEXTEND ON NEXT
10K MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT
AUTO;

SQL> CREATE SMALLFILE TABLESPACE "PRODUCTION" DATAFILE


'/oradata/TLSDMO/production01.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K MAXSIZE
UNLIMITED , '/oradata/TLSDMO/production02.dbf' SIZE 20M AUTOEXTEND ON NEXT 10K
MAXSIZE UNLIMITED ,'/oradata/TLSDMO/production03.dbf' SIZE 20M AUTOEXTEND ON NEXT
10K MAXSIZE UNLIMITED , '/oradata/TLSDMO/production04.dbf' SIZE 20M AUTOEXTEND ON
NEXT 10K MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT
AUTO;

SQL> set pages 2000 lines 100;


SQL> select table_name, tablespace_name, owner from dba_tables where owner =
'DEMO';

==============================================================================
2) move all tables in the DEMO schema to the DEMONSTATE tablespace
==============================================================================

SQL> conn demo/demo1

SQL> alter table departments move tablespace demonstate;

SQL>alter table employees move tablespace demonstate;

SQL> alter table jobs move tablespace demonstate;

SQL> alter table job_history move tablespace demonstate;

SQL> alter table regions move tablespace demonstate;

SQL>alter table locations move tablespace demonstate;

SQL> alter table countries move tablespace demonstate;

==============================================================================
3) move all tables in the DEV schema to the DEVELOPMENT tablespace
==============================================================================
sqlplus dev/dev1
SQL> show user
USER is "DEV"
SQL>alter table departments move tablespace development;

SQL> SQL> alter table employees move tablespace development;

SQL> SQL> alter table jobs move tablespace development;

SQL> SQL> alter table jobs move tablespace development;

SQL> SQL> alter table job_history move tablespace development;

SQL>alter table regions move tablespace development;

SQL>alter table locations move tablespace development;

SQL> alter table countries move tablespace development;

SQL> host

==============================================================================
4) move all tables in the QAT schema to the QATESTING tablespace
==============================================================================
sqlplus qat/qat1
SQL> show user
USER is "QAT"

SQL> alter table departments move tablespace qatesting;

SQL> SQL> alter table employees move tablespace qatesting;

SQL> alter table employees move tablespace qatesting;

SQL> alter table jobs move tablespace qatesting;

SQL>alter table job_history move tablespace qatesting;


SQL> alter table regions move tablespace qatesting;

SQL>alter table locations move tablespace qatesting;

SQL> alter table countries move tablespace qatesting;

SQL> host

==============================================================================
5) move all tables in the PROD schema to the PRODUCTION tablespace
==============================================================================

sqlplus prod/prod1
SQL> show user
USER is "PROD"
SQL>alter table departments move tablespace production;

SQL> alter table employees move tablespace production;

SQL> alter table jobs move tablespace production;

SQL>alter table job_history move tablespace production;

SQL> alter table regions move tablespace production;

SQL> alter table locations move tablespace production;

SQL> alter table countries move tablespace production;

Table altered.

SQL> host

SQL> set pages 2000 lines 100;


SQL> select table_name, tablespace_name, owner from dba_tables where owner =
'DEMO';

SQL> select table_name, tablespace_name, owner from dba_tables where owner = 'DEV';

SQL> select table_name, tablespace_name, owner from dba_tables where owner = 'QAT';

SQL> select table_name, tablespace_name, owner from dba_tables where owner =


'PROD';
=============================================================================
6) add a column called SSN with type NUMBER(6) to the EMPLOYEES table in the DEV
schema
==============================================================================
SQL> conn dev/dev1
Connected.
SQL> show user
USER is "DEV"
SQL> alter table employees add SSN Number (6);

SQL> set pages 2000 lines 100;

SQL> describe employees;


Done in ORCL

Please note that this assignment should be done in the HR Schema of the ORCL
database

SQL _Fundamentals_Practice_4.pdfView in a new window

ASSIGNMENT 5
===============
User Managed backup scenariosView in a new window
====================================================

CASE 1: Lost all the controlfiles


CASE 2: Lost System Datafile
CASE 3: Lost Non - System Datafiles
CASE 4: A added data file was lost after hot backup
CASE 5: Datafile lost and needs to be restored to different location
CASE 6: Lost everything including datafiles and controlfiles except for online redo
logs.
CASE 7: Lost a read only tablespace which was read only when backup was taken
CASE 8: Creating new Control File After Losing All Current and Backup Control
Files

######
Question: I understand that there are times that you need to force a log switch
for backups, but I have noted that Oracle has two ways to force a logfile switch,
ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVE LOG CURRENT.

What is the difference between ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVE
LOG CURRENT, and when do I use each?

Answer: Yes, both ALTER SYSTEM SWITCH LOGFILE and ALTER SYSTEM ARCHIVE LOG CURRENT
will force a log switch, but they do it in different ways!

Both the SWITCH LOGFILE and ARCHIVE LOG CURRENT write a quiesce checkpoint, a firm
place whereby that last redo log is a part of the hot backup, but ARCHIVE LOG
CURRENT waits for the writing to complete. This can take several minutes for
multi-gigabyte redo logs.

Conversely, the ALTER SYSTEM SWITCH LOGFILE command is very fast and returns
control to the caller in less than a second while ALTER SYSTEM ARCHIVE LOG CURRENT
pauses.

As we see below, the ALTER SYSTEM SWITCH LOGFILE is fast because it does not wait
for the archiver process (ARCH) to complete writing the online redo log to the
archivelog log filesystem:

*It issues database checkpoint


*It immediately starts writing to the next redo log
*In the background, the "switch logfile" command tells the ARCH background
process to copy the "old" redo log file to the redo log filesystem.
PART 1
Do on ORCL

SQL> show parameter recovery;


SQL> alter system set db_recovery_file_dest_size = 25G;
SQL> alter system set db_recovery_file_dest = '/oradata/FRA/';
SQL> show parameter recovery;
SQL> shutdown immediate
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;

O/S> mkdir -p /oradata/PROD_USER/ ##A repository dir to keep backups##

SQL> alter system switch logfile;

SQL> alter system archive log current;

SQL> select instance_name,status from v$instance;

SQL> alter database begin backup;

SQL> select file#,status from v$backup;


####in case one of the files is not in backup mode that is inactive put
that datafile in backup mode e.g alter datafile system begin backup#####
SQL> ! cp /oradata/PROD/* /oradata/PROD_USER/

SQL> alter database end backup;

####smon will rollforward from the scn when we started the backup to when we end
the backup###

SQL> select file#,status from v$backup;


####in case one of the files is still in backup mode when u end the backup ie
active put that datafile in end backup mode e.g alter datafile system end backup
#####

SQL> alter system switch logfile;

SQL> alter system archive log current;

==============================================================================
1-system-tablespace-loss ------------> 1b-recover-system-tablespace
remove /oradata/ORCL/system*.dbf
perform recovery on ORCL
==============================================================================
SQL> alter system switch logfile;

SQL> alter system archive log current;

SQL> alter database backup controlfile to trace as


'/oradata/HOT_BACKUP/ORtrolfile.sql';

O/S> cd /oradata/ORCL
ll
rm system01*.dbf
ll
. oraenv
db_name (to make sure u are connected)

sqlplus / as sysdba

SQL> shutdown abort

O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/system01.dbf .
ll
O/S> sqlplus / as sysdba

SQL> startup mount

SQL> recover tablespace system;

SQL> alter database open;

SQL> select status from v$instance;

==============================================================================
2-user-datafile-loss ----------------> 2b-recover-users-tablespace
remove /oradata/ORCL/user*.dbf
perform recovery on ORCL
==============================================================================

O/S> cd /oradata/ORCL
ll
rm users01.dbf
ll
. oraenv
db_name (to make sure u are connected)

sqlplus / as sysdba
###is a noncritical file so we don't have to shutdown the db###
SQL> alter tablespace users offline immediate;
###is like shutdown abort####
exit

O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/users01.dbf .
ll
O/S> sqlplus / as sysdba

SQL> select file_name,status from dba_data_files where tablespace_name='USERS';


## To make sure u copied###

SQL> recover tablespace users;

###when u see Media recovery complete bring the tbs online.###

SQL> alter tablespace users online;

##check tbs ststus###


SQL> select file_name,status from dba_data_files where tablespace_name='USERS';
======================================================================
3-example-datafile-loss -------------> 3b-recover-example-table
space
remove /oradata/ORCL/example*.dbf
perform recovery on ORCL
=======================================================================

O/S> cd /oradata/ORCL
ll
rm example01.dbf
ll
. oraenv
db_name (to make sure u are connected)

sqlplus / as sysdba

SQL> alter tablespace example offline immediate;


exit

O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/example01.dbf .
ll
O/S> sqlplus / as sysdba

OR

SQL> ! cp /oradata/HOT_BACKUP/ORCL/example01.dbf /oradata/ORCL/

SQL> select file_name,status from dba_data_files where tablespace_name='EXAMPLE';

SQL> recover tablespace example;

when u see Media recovery complete bring the tbs online.

SQL> alter tablespace example online;

##check tbs ststus###


SQL> select file_name,status from dba_data_files where tablespace_name='EXAMPLE';

=======================================================================
4-online-redo-loss ------------------> 4b-recover-from-redo-loss
remove /oradata/ORCL/redo*.log
perform recovery on ORCL
=======================================================================

SQL> alter system switch logfile;

SQL> alter system archive log current;


##update backup by cp from db to backup location before deleting###
O/S> cd /oradata/ORCL
ll
rm redo*.log
ll
. oraenv
db_name (to make sure u are connected)
sqlplus / as sysdba

SQL> alter system switch logfile;


SQL> alter system archive log current;

SQL> shutdown immediate


O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/redo*.log .

O/S> sqlplus / as sysdba

SQL> startup mount

OR
SQL> ! cp /oradata/HOT_BACKUP/ORCL/redo*.log /oradata/ORCL/

SQL> recover database using backup controlfile until cancel;

###when we use backup control file we have to open the database with reset
logs####

##copy the archive needed for the recovery and paste bellow specified log##
##when u see %u it means the is no more info in the archive log needed for this
recovery.we have to check for info in the redologs##
##when u see Media recovery complete open db##
SQL> alter database open resetlogs;

OR
##copy the archive needed for the recovery and paste bellow specified log if u
don't see media recovery open a new terminal##

## . oraenv
db_name
sqlplus / as sysdba
SQL> select name from v$log;
SQL> select name from v$logfile;
Specify log:
/oradata/ORCL/redo01.log

Media recovery complete.


SQL> alter database open resetlogs;
####if u don't want to open a second terminal take the log sequence number eg #14
divide by 3 and u will get the redo that has recovery ####
OR
Clear all unarchived logfile

SQL> alter database clear unarchived logfile group 1;

SQL> alter database clear unarchived logfile group 2;

SQL> alter database clear unarchived logfile group 3;

SQL> alter database open resetlogs;

###it is impt to backup the database after the restore and recovery of a
critical file###
SQL> alter database begin backup;

SQL> alter system switch logfile;

SQL> alter system archive log current;

SQL> !cp /oradata/ORCL/* /oradata/HOT_BACKUP/ORCL/

SQL> alter database end backup;

SQL> select file#,status from v$backup;

SQL> alter system switch logfile;

SQL> alter system archive log current;

SQL> select status from v$instance;

OR WE USE THE BACKUP CONTROLFILE


####we use the control file because when we creat the controlfile and open reset
logs it will create the redo logs####

on winscp
go to /oradata/ORCL
when editing skip reuse

==================================================================================
5-controlfile-loss ------------------> 5b-recover-from-controlfile-loss
remove /oradata/ORCL/*.ctl
perform recovery on ORCL
==================================================================================
. oraenv
db_name (to make sure u are connected)

O/S> sqlplus / as sysdba


O/S> cd /oradata/ORCL
ll
SQL> alter system switch logfile;
SQL> alter system archive log current;
rm control*.ctl
ll
. oraenv
db_name (to make sure u are connected)

sqlplus / as sysdba

SQL> alter system switch logfile;


SQL> alter system archive log current;

SQL> shutdown immediate


O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/control*.ctl .
O/S> sqlplus / as sysdba

SQL> startup mount

OR
SQL> ! cp /oradata/HOT_BACKUP/ORCL/control*.ctl /oradata/ORCL/

SQL> recover database using backup controlfile until cancel;

##copy the archive needed for the recovery and paste bellow specified log##
##when u see %u it means the is no more info in the archive log needed for this
recovery.we have to check for info in the redologs##
##when u see Media recovery complete open db##
SQL> alter database open resetlogs;

OR
##copy the archive needed for the recovery and paste bellow specified log if u
don't see media recovery open a new terminal##

## . oraenv
db_name
sqlplus / as sysdba
SQL> select name from v$log;
SQL> select name from v$logfile;
Specify log:
/oradata/ORCL/redo01.log

Media recovery complete.


SQL> alter database open resetlogs;

OR
Clear all unarchived logfile

SQL> alter database clear unarchived logfile group 1;

SQL> alter database clear unarchived logfile group 2;

SQL> alter database clear unarchived logfile group 3;

SQL> alter database open resetlogs;

####do a full backup###

=================================================================================
6-database-loss ---------------------> 6b-recover-from-total-loss
remove all files in /oradata/ORCL/*.*
perform recovery on ORCL
==================================================================================
. oraenv
db_name
sqlplus / as sysdba

SQL> alter system archive log current;

SQL> alter system switch logfile;


exit
cd /oradata/ORCL
ll
rm *
ll
sqlplus / as sysdba

SQL> shutdown abort


ORACLE instance shut down.
SQL> ! cp /oradata/HOT_BACKUP/ORCL/* /oradata/ORCL/

SQL> startup mount


SQL> recover database using backup controlfile until cancel;

##copy the archive needed for the recovery and paste bellow specified log##
##when u see %u it means the is no more info in the archive log needed for this
recovery.we have to check for info in the redologs##
##when u see Media recovery complete open db##
SQL> alter database open resetlogs;

OR
##copy the archive needed for the recovery and paste bellow specified log if u
don't see media recovery open a new terminal##

## . oraenv
db_name
sqlplus / as sysdba
SQL> select name from v$log;
SQL> select name from v$logfile;
Specify log:
/oradata/ORCL/redo01.log

Media recovery complete.


SQL> alter database open resetlogs;

OR
Clear all unarchived logfile

SQL> alter database clear unarchived logfile group 1;

SQL> alter database clear unarchived logfile group 2;

SQL> alter database clear unarchived logfile group 3;

SQL> alter database open resetlogs;

####do a full backup###

PART 2
=============

This assignment requires you to create a hotbackup of the ORCL database using
scripts and using that backup to create a database called REFRESH. Please all work
together to get this done

******db cloning -- what is it and why


What is Database cloning?
What are the procedures involved in cloning a database?
What are the advantages & uses?
cloning is as it sounds -- making a copy of. It is basically taking a backup of an
instance and restoring it elsewhere. You've "cloned" the database.

Procedures are: backup, restore it elsewhere (typically on another machine in


exactly the same directory structure but you can restore it onto the same machine,
you'll want to change the sid and database name, see
Advantages and uses -- people use it to test with mostly. You clone a production
instance onto a test machine to try out new things ******

A) MAKE THE FOLLOWING DIRECTORIES IN THE LOCATION SPECIFIES

USING WINSCP( OR OPERATING SYSTEM)

1) /oradata/REFRESH/(clone)

2) /u01/app/oracle/admin/REFRESH/adump (clone)

3) /etc/oratab (set environment) (clone)


REFRESH:/u01/app/oracle/product/11.2.0/db_1:N

4) /oradata/FRA/REFRESH/archivelog (clone)

B) IN YOUR SOURCE DATABSE (ORCL)

1) SQL> CREATE PFILE FROM SPFILE;

2) SQL> alter database backup controlfile to trace as


'/oradata/REFRESH/controlfile.sql'

3) SQL> alter system archive log current;

4) SQL> alter database begin backup;

5) SQL> ! cp /oradata/ORCL/* /oradata/REFRESH/

SQL> ! cp /oradata/ORCL/* /oradata/REFRESH/ &

6) SQL> alter database end backup;

7)SQL> alter system archive log current;

####it is impt to do archive log bec users where still writing to the db when u
put the db in backup mode####

8) SQL> ! cp -r /oradata/FRA/ORCL/archivelog/ /oradata/FRA/REFRESH/


****copy archive log from the FRA of remote to target db bec we need the archive
log in the FRA of the target db for recovery of the target db*****

C) IN WINSCP AGAIN

1) DUPLICATE pfile initORCL.ora to initREFRESH.ora

2) EDIT initREFRESH.ora (replace ORCL WITH REFRESH)


3) Delete control01.ctl & control02.ctl files from /oradata/REFRESH/

4) EDIT controlfile.sql (in /oradata/REFRESH/controlfile.sql

D) IN OPERATIING SYSTEM

1) DEFINE ENVIRONMENT . oraenv REFRESH


2) sqlplus / as sysdba

3) connect to an idle instance ( very important for control file to be created)

4) SQL> CREATES SPFILE FROM PFILE

5)SQL> @/oradata/REFRESH/controlfile.sql ( results control file created)

6) SQL recover database using backup controlfile until cancel;

7) copy and paste the archive log sequences until you get or similar

/oradata/FRA/REFRESH/archivelog/2018_08_20/o1_mf_1_11_%u_.arc
ORA-00308: cannot open archived log
'/oradata/FRA/REFRESH/archivelog/2018_08_20/o1_mf_1_11_%u_.arc' ****is telling us
that the
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

7) alter database open resetlogs;

Database altered.

15)CREATE A DATABASE FROM A BACKUP (HOT CLONE)


==========================================================
this is a new database and we have to do some prerequisite checks(datafiles,
controlfiles, redolog files, adump, oratab, archivelog, parameter file) to start up
the new database
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
1-DATAFILES: we have to copy to the datafiles from the backup location HRPRD_BACKUP
to the new database /oradata/CATALOG/
-----------------------------------------------------------------------------------
----------------------------------------

[oracle@student123 ~]$ mkdir -p /oradata/CATALOG/

either you go to winscp and copy the files or you do it on command line
-------------------------------------------------------------------------
on command line
----------------
[oracle@student123 CATALOG]$ cp /oradata/HRPRD_BACKUP/* . ** in case
this is copy from remote to pwd, meaning i am in the catalog database and i am
copying from /oradata/HRPRD_BACKUP/ to where i am(.)

validate that the files are in catalog database


------------------------------------------------
[oracle@student123 ~]$ cd /oradata/CATALOG/

[oracle@student123 ~]$ ll

OR on winscp
--------------
navigate to /oradata/HRPRD_BACKUP/
-------------------------------------
highlight all the files in HRPRD_BACKUP and click duplicate. change the path you
see from /oradata/HRPRD_BACKUP/*.* TO '/oradata/CATALOG/*.* and click ok. it will
copy all the files from HRPRD_BACKUP TO CATALOG
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------------------------------------
wait until it is done.If you see abort, reconnect(58sec), DONOT CLICK ABORT, else
it will end half way and no all the files will be copied
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------
navigate to /oradata/CATALOG/ to make sure the files are there.
----------------------------------------------------------------

2) CONTROLFILES: we copied all the files from HRPRD_BACKUP to CATALOG including the
controlfiles of the old db(HRPRD). we have to delete these controlfiles(bc they
belong to the old db) and then use the one we backup to trace to recreate the
controlfiles of our new db)
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------
ON WINSCP: after deleting control01.dbf, control02.dbf and so on....do the
following
-------------------------------------------------------------------------
open the controlfile backup to trace(hrprd_ctl.sql) and edit it
--------------------------------------------------------------------------------
remove everything above startup mount and everything below character;
--------------------------------------------------------------------------
HIGHLIGHT EVERYTHING and change everything having HRPRD to CATALOG (you need to
highlight everything because if you dont, not everything will change)
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---
change REUSE at the top of the script to SET and NORESETLOGS to RESETLOGS and save
the script (you want your database to start with new redologs). SAVE THE FILE
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--

3) REDOLOG FILES: these files were already copied with the datafiles from
/oradata/HRPRD_BACKUP/ to /oradata/CATALOG/
-----------------------------------------------------------------------------------
------------------------------

4)ADUMP: navigate to /u01/app/oracle/admin/ and create the directory for the


database and adump
-----------------------------------------------------------------------------------
------------
[oracle@student123 ~]$ mkdir -p /u01/app/oracle/admin/CATALOG

[oracle@student123 ~]$ mkdir -p /u01/app/oracle/admin/CATALOG/adump

5) ORATAB: Navigate to the oratab file and add the oracle_home for that database
---------------------------------------------------------------------------------
[oracle@student123 ~]$ vi /etc/oratab/ *** add the line below**

CATALOG:/u01/app/oracle/product/11.2.0/db_1:N

6) ARCHIVELOG: we have to copy the archivelog directory of HRPRD across to the


CATALOG database because we did an inconsistent backup which WE would need recovery
if we want the catalog database to open
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------
create the directory for CATALOG in FRA and archivelog
---------------------------------------------------------
[oracle@student123 ~]$ mkdir -p /oradata/FRA/CATALOG/

[oracle@student123 ~]$ mkdir -p /oradata/FRA/CATALOG/archivelog/

[oracle@student123 ~]$ cp -r /oradata/FRA/HRPRD/archivelog/


/oradata/FRA/CATALOG/archivelog/ &

7) PARAMETER FILE: go to winscp and navigate to the location of the pfile of HRPRD
-----------------------------------------------------------------------------------
-------
path is:

/u01/app/oracle/product/11.2.0/db_1/dbs

look for initHRPRD.ora, right click on it and make a duplicate. Change the path of
the pfile from /u01/app/oracle/product/11.2.0/db_1/dbs/initHRPRD.ora to
/u01/app/oracle/product/11.2.0/db_1/dbs/initCATALOG.ora
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------------------
enter the pfile of CATALOG(initCATALOG.ora) and change the contents from HRPRD to
CATALOG, then save the file.
-----------------------------------------------------------------------------------
--------------------------------

now are done with the necessary set to clone HRPRD TO CATALOG
---------------------------------------------------------------
go back to putty and set your environment to CATALOG
-----------------------------------------------------

[oracle@student123 ~]$ . oraenv

ORACLE_SID = [DB11G] ? CATALOG

startup nomount using the pfile.


------------------------------------
[oracle@student123 ~]$ sqlplus / as sysdba

SQL> startup nomount pfile='$ORACLE_HOME/dbs/initCATALOG.ora';

RUN THE SCRIPT TO RECREATE THE CONTROLFILE.(remember you edited this script and it
is found in /oradata/CATALOG/)
-----------------------------------------------------------------------------------
-------------------------------
SQL> @/oradata/CATALOG/hrprd_ctl.sql
<<<this is the location of the script>>>

control file created.

now since the backup you did was in inconsistent, we need recovery.
-----------------------------------------------------------------------

SQL> recover database using backup controlfile until cancel;

something like this should appear.

ORA-00279: change 2257741 generated at 06/24/2018 00:02:12 needed for thread 1


ORA-00289: suggestion :
/oradata/FRA/ORCL/archivelog/2018_06_24/o1_mf_1_67_.arc <<<<<<<<-------copy
this whole path and paste under specify log.this is why you need to switch log as
we did above so that what is in the archivelog will be used for this recovery.
ORA-00280: change 2257741 for thread 1 is in sequence #67

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

to specify the log, copy the path and paste it under specify log. the path indicate
by arrow above
/oradata/FRA/ORCL/archivelog/2018_06_24/o1_mf_1_67_.arc
<<<after pasting press enter>>>

>keep on copying the path and pasting until you see that the file path has %U.
(these files are needed because you performed incomplete backup above,so recovery
is needed from the archivelog which you transfered)
>if the same error appears, with the file path having %U it means, recovery is
complete. type CANCEL under specify log
eg '/oradata/FRA/CATALOG/archivelog/2018_06_24/o1_mf_1_6_%u_.arc' (recovery is
complete)

you should reset the logs


----------------------------

SQL> alter database open resetlogs;

database altered.

ASSIGNMENT 6
================

PART1:

===============================================================================
1) Perform a user managed (hot) backup of your TLSDMO Database using backup
Location: /oradata/TLSDMO_BACKUP
==================================================================================
. oraenv
TLSDMO
O/S> mkdir -p /oradata/TLSDMO_CONTROLFILE

SQL> alter database backup controlfile to trace as


'/oradata/TLSDMO_CONTROLFILE/controlfile.sql';

. oraenv
TLSDMO
O/S> mkdir -p /oradata/TLSDMO_BACKUP

O/S> sqlplus / as sysdba

SQL> select instance_name,status from v$instance;

SQL> show parameter recovery; ***check if the database is in recovery mode***

SQL> archive log list; ***check if the database is in archive log mode***

SQL> alter system switch logfile; ***to force log switch and send everything to
the archive log and will not wait for uses to finish their transaction is like
shutdown abort.it can also cause a fracture block ie if a transaction was going on
it will not wait for it to finish****

SQL> alter system archive log current;****archive log current will wait for all
incoming transaction before it will switch****

SQL> alter database begin backup; ***put the database in backup mode i.e we queeze
the *****

SQL> select file#,status from v$backup;**check if the database is in backup mode**

SQL> !cp /oradata/TLSDMO/* /oradata/TLSDMO_BACKUP/

SQL> alter database end backup;

SQL> select file#,status from v$backup;

SQL> alter system switch logfile;

SQL> alter system archive log current;

SQL> select status from v$instance;

==============================================================================
2) create a recovery catalog owner called rmanbrontech1 in your RCAT database
==============================================================================
. oraenv
RCAT
O/S> sqlplus / as sysdba

SQL> show parameter recovery; ***check if the database is in recovery mode***

SQL> archive log list; ***check if the database is in archive log mode***

SQL> create user rmanbrontech identified by rmanbrontech;


SQL> grant connect, resource, recovery_catalog_owner to rmanbrontech;

SQL> create tablespace CATT datafile '/oradata/RCAT/catt01.dbf' size 25M;

make the tbs auto extern

SQL> alter user rmanbrontech identified by rmanbrontech default tablespace CATT;


O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT
RMAN> create catalog;

================================================================================
3) register the TLSDMO database in your recovery catalog
================================================================================
. oraenv
TLSDMO
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT

RMAN> register database;

==================================================================================
5) catalog the backup made in step 1
==================================================================================

RMAN> catalog start with '/oradata/TLSDMO_BACKUP/';

####this failure occur bec rman does not catalog redo log file and control file but
it catalog archive log and and the control file only when it ends with .bin ###
##### List of Files Which Where Not Cataloged
=======================================
File Name: /oradata/TLSDMO_BACKUP/redo01.log
RMAN-07529: Reason: catalog is not supported for this file type
File Name: /oradata/TLSDMO_BACKUP/control02.ctl
RMAN-07519: Reason: Error while cataloging. See alert.log.
File Name: /oradata/TLSDMO_BACKUP/control01.ctl
RMAN-07519: Reason: Error while cataloging. See alert.log.
File Name: /oradata/TLSDMO_BACKUP/redo03.log
RMAN-07529: Reason: catalog is not supported for this file type
File Name: /oradata/TLSDMO_BACKUP/redo02.log
RMAN-07529: Reason: catalog is not supported for this file type#########

PART2:

=================================================================================
Remove both the system and sysaux tablespaces via RMAN and perform recovery using

list failure
advise failure
repair failure
==================================================================================
. oraenv
TLSDMO
O/S> cd /oradata/TLSDMO
ll
O/S> rm system01.dbf sysaux01.dbf
ll
O/S> sqlplus / as sysdba
SQL> select status from v$instance;
SQL> shutdown abort
SQL> startup mount;
exit
O/S> rman target /

RMAN> list failure all;

RMAN> advise failure;

RMAN> repair failure;

yes

ASSIGNMENT 7

TLSDMO

==============================================================================
1) configure auto backup on
==============================================================================
. oraenv
TLSDMO
O/S> rman target /
RMAN> show all;

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

###when turn on it will backup the control file and spfile#####

================================================================================
2) Configure block change tracking
=================================================================================
. oraenv
TLSDMO
ll

O/S> mkdir -p /oradata/BLOCK_CHANGE/tlsdmo/

O/S> sqlplus / as sysdba

SQL> alter database enable block change tracking using file


'/oradata/BLOCK_CHANGE/tlsdmo/change_tracking.dbf';

###Block change tracking back just the changes that toook place in the database ###

==================================================================================
3) perform a level 0 backup
==================================================================================

O/S> rman target /

O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT;

RMAN> backup incremental level 0 database;

exit
O/S> sqlplus / as sysdba

SQL> create table demo.brontech as select * from demo.jobs;

SQL> insert into demo.brontech select * from demo.jobs;

SQL> create table demo.class as select * from demo.employees;

SQL> insert into demo.class select * from demo.employees;

SQL> commit;

###we craete the table so as to

===========================================================================
4) perform a level 1 backup
============================================================================

O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT

RMAN> backup incremental level 1 database;

exit

=================================================================================
5) perform an image copy backup ( datafiles, archivelogs, spfile, controlfile) to
location /oradata/TLSDMO_IMAGE_COPY/
==================================================================================

O/S> mkdir -p /oradata/TLSDMO_IMAGE_COPY/

O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT

RMAN> backup as copy database format '/oradata/swcopy/%u';

RMAN> backup as copy spfile format '/oradata/TLSDMO_IMAGE_COPY/copy_spfile.ora';

RMAN> backup as copy current controlfile format


'/oradata/TLSDMO_IMAGE_COPY/copy_controlfile.ctl';

RMAN> backup as copy datafile 1 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 2 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 3 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 4 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 5 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 6 format '/oradata/TLSDMO_IMAGE_COPY/%u';

RMAN> backup as copy datafile 7 format '/oradata/TLSDMO_IMAGE_COPY/%u';


ASSIGNMENT 8
============

Part1

TLSDMO

========================================================================
1) Perform an image copy backup of the following datafiles to /oradata/
=========================================================================

/oradata/TLSDMO/psimgr.dbf

/oradata/TLSDMO/psindex.dbf

****make sure the catalog and target databases are up and running****
. oraenv
RCAT
sqlplus / as sysdba
SQL> select database_name, status from v$instance;
exit

. oraenv
TLSDMO
mkdir -p /oradata/TLSDMO_COPY
sqlplus / as sysdba
exit
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT

RMAN> backup as copy datafile 24 format '/oradata/TLSDMO_COPY/psindex.dbf';

RMAN> backup as copy datafile 39 format '/oradata/TLSDMO_COPY/psimgr.dbf';

===============================================================================
2) Perform a "switch datafile to copy" of the following datafiles
===============================================================================

/oradata/TLSDMO/psimgr.dbf

/oradata/TLSDMO/psindex.dbf

RMAN> report schema;

RMAN> sql 'alter database datafile 24,39 offline';

RMAN> switch datafile 24,39 to copy;

RMAN> recover datafile 24,39;

RMAN> sql 'alter database datafile 24,39 online';

RMAN> report schema;


RMAN> BACKUP AS COPY DATABASE FORMAT '/oradata/TLSDMO_COPY/%u';

TO SWITCH BACK TO THE DATAFILE

cd /oradata/TLSDMO
LL
O/S> rm psindex.dbf psimgr.dbf
LL
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT;

RMAN> backup as copy datafile 24 format '/oradata/TLSDMO/psindex.dbf';

RMAN> backup as copy datafile 39 format '/oradata/TLSDMO/psimgr.dbf';

RMAN> report schema;

Part 2

TLSDMO

1) Perform a backup based duplication of TLSDMO to TLSDMO2

. oraenv
TLSDMO
O/S> mkdir -p /oradata/TLSDMO_COPY2/
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT;

RMAN> RMAN> run{


backup as copy database format '/oradata/TLSDMO_COPY2/%u';
backup as copy spfile format '/oradata/TLSDMO_COPY2/copy_spfile.ora';
backup as copy archivelog all format '/oradata/TLSDMO_COPY2/arch_%u.arc';
backup as copy current controlfile format
'/oradata/TLSDMO_COPY2/copy_controlfile.ctl';
}

RMAN> show all;

RMAN> CONFIGURE BACKUP OPTIMIZATION ON;

RMAN> exit

c) edit the pfile of TLSDMO2:

- replace all TLSDMO with TLSDMO2


-add these two lines:

###if u switched datafiles from backup location to datafiles add this


2lines####

*.db_file_name_convert='/oradata/TLSDMO/','/oradata/CRMPRD/'
*.log_file_name_convert='/oradata/TLSDMO/','/oradata/CRMPRD/'

###if u have not switch datafiles from backup location to datafiles


add this 4lines####
*.db_file_name_convert =
'/oradata/TLSDMO/','/oradata/TLSDMO2/','/oradata/TLSDMO_COPY/','/oradata/TLSDMO2/'
*.log-file_name_convert =
'/oradata/TLSDMO/','/oradata/TLSDMO2/','/oradata/TLSDMO_COPY/','/oradata/TLSDMO2/'

d) create the necessary directories:

O/S> mkdir -p /u01/app/oracle/admin/TLSDMO2/


O/S> mkdir -p /u01/app/oracle/admin/TLSDMO2/adump/
O/S> mkdir -p /oradata/TLSDMO2/
O/S> mkdir -p /oradata/FRA/TLSDMO2/

e) Edit /etc/oratab: (Winscp)

f) startup TLSDMO2 nomount with the pfile:

. oraenv
TLSDMO
sqlplus / as sysdba
SQL> startup nomount pfile = '$ORACLE_HOME/dbs/initTLSDMO2.ora';
exit
rman auxiliary /

RMAN> duplicate target database to TLSDMO2 backup location '/oradata/TLSDMO_COPY2/'


nofilenamecheck;

. oraenv
TLSDMO2
O/S> sqlplus / as sysdba
SQL> select status from v$instance;

SQL> select member from v$logfile;

Assignment 9
==============

Tablespace point in time recovery

=================================================================================
1) Create an additional tablespace in ORCL called student
===============================================================================

. oraenv

ORCL

**create dir**
O/S> mkdir -p /oradata/AUX_DEST/
sqlplus / as sysdba
SQL> select status from v$instance;

**checking my table space and its status**


SQL> select tablespace_name, status,contents from dba_tablespaces;

sql> create tablespace STUDENT datafile '/oradata/ORCL/student.dbf' size 10M;

**vaildating if the table is created**


SQL> select tablespace_name, status,contents from dba_tablespaces;

** checking my time stamp**

SQL> SELECT SYSTIMESTAMP FROM DUAL;


SQL> set time on;

**checking my SCN time**

SQL> select timestamp_to_scn(sysdate) scn from dual;


SQL> SELECT CURRENT (*) FROM TUESDAY.TUESDAY;
SQL> select current_scn from v$database;
SQL> select timestamp_to_scn(to_timestamp('24/09/2012 14:24:54','DD/MM/YYYY
HH24:MI:SS')) as scn from dual;

sql> create user CLASS1 identified by class1 default tablespace STUDENT quota
unlimited on STUDENT;

SQL> alter user CLASS1 quota unlimited on student;

SQL> create table CLASS1.emp as select * from scott.emp;

**pluging data into the user in the student**


SQL> select count(*) from nana2.emp;

COUNT(*)
----------
14

SQL> insert into CLASS1.emp select * from CLASS1.emp;


SQL> commit;

SQL> select count(*) from CLASS1.emp;

COUNT(*)
----------
14

** checking my time stamp**


SQL> SELECT SYSTIMESTAMP FROM DUAL;
SQL> set time on;

**checking my SCN time**


SQL> select timestamp_to_scn(sysdate) scn from dual;
SQL> SELECT CURRENT (*) FROM TUESDAY.TUESDAY;

SQL> select current_scn from v$database;


SQL> select timestamp_to_scn(to_timestamp('24/09/2012 14:24:54','DD/MM/YYYY
HH24:MI:SS')) as scn from dual;

exit

**geting ready to perfrom my recovery using rman**

o/s> rman target /


RMAN> backup incremental level 0 database;
RMAN> backup current controlfile;
exit
SQL> set time on;
SQL> drop tablespace STUDENT including contents and datafiles;
exit
O/S> rman target /

RMAN> recover tablespace STUDENT until scn 2195406


auxiliary destination '/oradata/AUX_DEST';

<<<<<==== using sequence number use thi command***


RMAN> recover tablespace student until sequence 54 auxiliary destination
'/oradata/tspitr';

<<<<====== using SCN number use this command***


RMAN> recover tablespace student until SCN 54 auxiliary destination
'/oradata/tspitr';

<<<<==== using time to recover ****


RMAN> recover tablespace student until time "to_date('14-JAN-18
10.27.24','dd-mon-rrrr hh24:mi:ss')" auxiliary destination
'/oradata/tspitr';

RMAN> exit

**after the recovery of the student tabalesapce**

SQL> select tablespace_name,status from dba_tablespaces;

SQL> alter tablespace STUDENT online;


SQL> alter database datafile '/oradata/ORCL/student.dbf' online;
exit
O/S> rman target /
RMAN> backup incremental level 1 database;

****dont wear some ones suit bec it will not fit u


what u are not make up off u can never make out of it ,it is just a matter of time
the real u will show up and pple will see u*******
when u use what god has not given u it will not work
dont sell clothes bec u c pple selling
few with god is more than the majority********

2) Take a complete backup of the database.

o/s> rman target /


RMAN> backup incremental level 0 database;
RMAN> backup current controlfile;
exit
3) Wait 10mins and Perform a Tablespace Point In Time Recovery based on 5mins ago
of the student tablespace

O/S> rman target /

RMAN> recover tablespace STUDENT until scn 2195406 auxiliary destination


'/oradata/AUX_DEST'; ****considered as time when the database was working
well*****

SQL> select tablespace_name,status from dba_tablespaces;

SQL> alter tablespace STUDENT online;


SQL> alter database datafile '/oradata/ORCL/student.dbf' online;
exit
SQL> select instance_name, status from v$instance;

SQL> select name from v$tablespace;

select name from v$datafile;


O/S> rman target /
RMAN> backup incremental level 1 database;

Transportable tablespace

1) Transport tablespaces ptwork, ptapp, pswork, pttree from TLSDMO to ORCL


. oraenv
TLSDMO
sqlplus / as sysdba

SQL> select name from v$tablespace;


SQL> select status from v$instance;
SQL> select name from v$datafile;
SQL> select * from v$tablespace;

**creating the logical called TLSDUMP directory**


SQL> create or replace directory monday as '/oradata/';
SQL> create or replace directory TLSDUMP as '/oradata/TRANSPORT/';
SQL> grant read, write on directory TLSDUMP to system;

**checking to see the status of the table spaces we want to transport**


SQL> select tablespace_name, contents, status from dba_tablespaces;

**putting all the 4 tablespaces we want to transfer in read mode**


SQL> alter tablespace pttree read only;
SQL> alter tablespace ptapp read only;
SQL> alter tablespace ptwork read only;
SQL> alter tablespace pswork read only;

**checking to see if tablespace is in read mode***


SQL> select tablespace_name, contents, status from dba_tablespaces;

SQL> create smallfile temporary tablespace "TEMP2" tempfile


'/oradata/TLSDMO/temp02.dbf' size 10M autoextend on next 12k maxsize
unted extent management local uniform size 1m;
SQL> alter database default temporary tablespace TEMP2;

**creating the logical directory by doing "touch" in /oradata/**


O/S> touch /oradata/trans_exp.par
OR
O/S> cd /oradata/TRANSPORT/
O/S> touch trans_exp.par

**"vi" and "cat" the diredctory to put the export command**


O/S> vi trans_exp.par

DIRECTORY=TLSDUMP <<<<< logical directory name


DUMPFILE=transport.dmp <<<<===== the dump directory name
LOGFILE=transport.log
TRANSPORT_TABLESPACES=PTTREE,PSWORK,PTAPP,PTWORK
<<<<<<=== and the names of the tablespace sapces been transfer**

O/S> cat trans_exp.par

<<<<<< here is the export command


O/S> expdp system/brontech1 parfile=/oradata/TRANSPORT/trans_exp.par

****coping the read only date to the target database*****

O/S>
cp -r /oradata/TLSDMO/pswork.dbf /oradata/ORCL/
cp -r /oradata/TLSDMO/ptapp.dbf /oradata/ORCL/
cp -r /oradata/TLSDMO/ptwork.dbf /oradata/ORCL/
cp -r /oradata/TLSDMO/pttree.dbf /oradata/ORCL/
sqlplus / as sysdba

***validating if the data was copied***


O/S> cd /oradata/ORCL
ll

SQL> select status from v$instance;


SQL> select name from v$database;

***removed the 4 tablespace back to read write mode =" online "***

SQL> alter tablespace pttree read write;

SQL> alter tablespace pswork read write;

SQL> alter tablespace ptapp read write;

SQL> alter tablespace ptwork read write;

***checking the status of the new read write tablespace***

SQL> select tablespace_name, contents, status from dba_tablespaces;

============================================================================
2) Remap schema from sysadm to hr
============================================================================
IN ORCL
. oraenv
ORCL

sqlplus / as sysdba
SQL> select status from v$instance;

**in the target u most create a lorgical directory and grant it read write**

SQL> create or replace directory ORCLDUMP as '/oradata/';


SQL> grant read,write on directory ORCLDUMP to system;

SQL> create or replace directory ORCLDUMP as '/oradata/TRANSPORT/';

SQL> grant read, write on directory ORCLDUMP to system;

SQL> select tablespace_name, contents, status from dba_tablespaces;

SQL> select username from dba_users;


exit

***<<<< creating my physical direcotry***


O/S> cd /oradata/TRANSPORT
touch trans_imp.par

vi trans_imp.par
***putting data into my par-file for import***
DIRECTORY=ORCLDUMP
DUMPFILE=transport.dmp
LOGFILE=transport.log
TRANSPORT_DATAFILES='/oradata/ORCL/pswork.dbf'
TRANSPORT_DATAFILES='/oradata/ORCL/ptwork.dbf'
TRANSPORT_DATAFILES='/oradata/ORCL/ptapp.dbf'
TRANSPORT_DATAFILES='/oradata/ORCL/pttree.dbf'
REMAP_SCHEMA=SYSADM:HR

cat trans_imp.par

**import command***
O/S> impdp system/brontech1 parfile=/oradata/TRANSPORT/trans_imp.par
sqlplus / as sysdba
SQL> select instance_name, status from v$instance;

SQL> select tablespace_name, contents, status from dba_tablespaces;

*** putting the import tables now in online mode= read write mode***
SQL> alter tablespace pswork read write;

SQL> alter tablespace ptwork read write;

SQL> alter tablespace ptapp read write;

SQL> alter tablespace pttree read write;

*validating after all the tablespace that have been transfer put back online**
SQL> select tablespace_name, contents, status from dba_tablespaces;
SQL> select tablespace_name, file_name from dba_data_files where
tablespace_name = 'PTTREE';
SQL> select name from v$datafile;
===================================================================================
==================================================================

10 ASSIGNMENT
===============
FLASHBACK
---------------

Flashback at row and table level

=================================================================================
1. Row level flashback
=================================================================================
. oraenv
O/S> TLSDMO
O/S> sqlplus / as sysdba

****Requirement for FlashbacK*****


Database must be in Archive log mode
Must have flash recovery area enable

****Setting the location of the flashback recovery area****


SQL> show parameter recovery;
SQL> alter system set db_recovery_file_dest = '/oradata/FRA/';

SQL> alter system set db_recovery_file_dest_size = 15G;

SQL> show parameter recovery;

**Setting the retention time for flashback files (in minutes) � 2 days***

SQL> alter system set DB_FLASHBACK_RETENTION_TARGET = 2880;

**Verify the Database in flash back mode and the retention_target***


SQL> SELECT flashback_on, log_mode FROM v$database;

*****How to Enable Flashback


Flashback query is not enabled by default and must be turned on in following
sequence. We will set retention to 10 hours (600 minutes) and set recovery size up
to 2 GB in file �/recovery/flashback�******

SQL> shutdown immediate;

SQL> startup mount

SQL> alter database flashback on;

SQL> alter database open;

SQL> show parameter undo_management;

SQL> alter system set undo_retention=3600;


SQL> show parameter undo_management;

SQL> show parameter undo_tablespace;

SQL> alter tablespace UNDOTBS1 retention guarantee;


SQL> select tablespace_name, status,contents from dba_tablespaces;

SQL> create user EXAM identified by exam default tablespace PRODUCTION;

SQL> grant connect,resource to EXAM;


SQL> create table exam.emp as select * from scott.emp;

SQL> alter table exam.emp enable row movement;


SQL> select count(*) from exam.emp;
SQL> select current_scn from v$database;

SQL> insert into exam.emp select * from exam.emp;

SQL> commit;

SQL> select count(*) from exam.emp;

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
3833131

SQL> flashback table exam.emp to scn 3832989;

SQL> select count(*) from exam.emp;

===========================================================================
2.Flashback drop table
===========================================================================

SQL> drop table exam.emp;

SQL> select count(*) from dba_tables;

SQL> flashback table exam.emp to before drop;

SQL> select count(*) from dba_tables;

SQL> select current_scn from v$database;

===========================================================================
3.Flashback drop user
===========================================================================
SQL> select current_scn from v$database;

SQL> drop user EXAM cascade;

SQL> shutdown immediate


SQL> startup mount

SQL> flashback database to scn 3833314;

SQL> alter database open resetlogs;


SQL> select status from v$instance;

SQL> desc exam.emp;

SQL> select * from exam.emp;

ASSIGNMENT 12
===============
Transparent Data Encryption
==============================

TLSDMO

==========================================================================
1) Create an encrypted tablespace called PEOPLETOOLS
===========================================================================

O/S> mkdir /oradata/wallet/

cd $ORACLE_HOME/network/admin
ll

vi sqlnet.ora

ENCRYPTION_WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=
(DIRECTORY=/oradata/wallet)))

O/S> ls -ltr /oradata/wallet

SQL> ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY "brontech1";

O/S> ls -ltr /oradata/wallet

SQL> create tablespace PEOPLETOOLS datafile '/oradata/TLSDMO/peopletools.dbf'


size 20M autoextend on extent management local autoallocate encryption using
'AES128' default storage(encrypt);

SQL> select tablespace_name,encrypted from dba_tablespaces where


tablespace_name='PEOPLETOOLS';

TABLESPACE_NAME ENC
------------------------------ ---
PEOPLETOOLS YES
SQL> select tablespace_name,encrypted from dba_tablespaces;

SQL> create user mercy identified by mercy1 default tablespace


PEOPLETOOLS quota unlimited on PEOPLETOOLS;

SQL> grant connect, resource to mercy;

SQL> select * from sysadm.psoprdefn;

===========================================================================
2) Copy move the table SYSADM.PSOPRDEFN to the tablespace PEOPLETOOLS
===========================================================================
SQL> alter table SYSADM.PSOPRDEFN move tablespace PEOPLETOOLS;

O/S> strings '/oradata/TLSDMO/peopletools.dbf'

==========================================================================
3) Perform a datapump export of the PEOPLETOOLS tablespace
==========================================================================

SQL> create or replace directory expdir as '/oradata/';

SQL> grant read, write on directory expdir to system;

SQL> alter tablespace PEOPLETOOLS read only;

>>>.CONFIGURE THE WALLET AUTO_LOGIN>>>>>>>

O/S> orapki wallet create -wallet /oradata/TLSDMO/wallet -auto_login -pwd


"MyPassword123"

O/S> expdp system/brontech1 directory=expdir dumpfile=exp.dmp logfile=exp.log


transport_tablespaces=PEOPLETOOLS

SQL> alter tablespace peopletools read write;

Вам также может понравиться