Академический Документы
Профессиональный Документы
Культура Документы
======================
DATABASE LINK
=======================
============================================================
NB. Make sure that the HR user password in the ORCL Database is set to HR
==============================================================
============================================================
Create a database link such that i am able to log in to TLSDMO and view the HR
schema in ORCL
===============================================================
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
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
==========================================================
=================================================================================
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';
=================================================================================
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;
==================================================================================
sqlplus DEMO/demo1
==================================================================================
sqlplus QAT/qat1
SQL> show user
USER is "QAT"
SQL> create table regions as select * from hr.regions@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> commit;
===========================================================================
SQL> commit;
==============================================================================
sqlplus PROD/prod1
SQL> show user
USER is "PROD"
SQL> insert into countries select * from hr.countries@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> 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> commit;
SQL> host
==============================================================================
sqlplus dev/dev1
SQL> show user
USER is "DEV"
SQL> update employees set last_name='BRONTECH';
SQL> commit;
SQL> host
==============================================================================
SQL> commit;
SQL> host
==============================================================================
sqlplus prod/prod1
SQL> update employees set last_name='BRONTECH';
SQL> commit;
==============================================================================
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> commit;
SQL> host
==============================================================================
sqlplus dev/dev1
SQL> show user
USER is "DEV"
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> commit;
SQL> host
==============================================================================
sqlplus qat/qat1
SQL> show user
USER is "QAT"
SQL> update departments set department_name='SCHOOL' where department_id='170';
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)
==============================================================================
==============================================================================
2) move all tables in the DEMO schema to the DEMONSTATE tablespace
==============================================================================
==============================================================================
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> host
==============================================================================
4) move all tables in the QAT schema to the QATESTING tablespace
==============================================================================
sqlplus qat/qat1
SQL> show user
USER is "QAT"
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;
Table altered.
SQL> host
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';
Please note that this assignment should be done in the HR Schema of the ORCL
database
ASSIGNMENT 5
===============
User Managed backup scenariosView in a new window
====================================================
######
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:
####smon will rollforward from the scn when we started the backup to when we end
the backup###
==============================================================================
1-system-tablespace-loss ------------> 1b-recover-system-tablespace
remove /oradata/ORCL/system*.dbf
perform recovery on ORCL
==============================================================================
SQL> alter system switch logfile;
O/S> cd /oradata/ORCL
ll
rm system01*.dbf
ll
. oraenv
db_name (to make sure u are connected)
sqlplus / as sysdba
O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/system01.dbf .
ll
O/S> sqlplus / as sysdba
==============================================================================
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
O/S> cd /oradata/ORCL
ll
rm example01.dbf
ll
. oraenv
db_name (to make sure u are connected)
sqlplus / as sysdba
O/S> cd /oradata/ORCL
ll
O/S> cp /oradata/HOT_BACKUP/ORCL/example01.dbf .
ll
O/S> sqlplus / as sysdba
OR
=======================================================================
4-online-redo-loss ------------------> 4b-recover-from-redo-loss
remove /oradata/ORCL/redo*.log
perform recovery on ORCL
=======================================================================
OR
SQL> ! cp /oradata/HOT_BACKUP/ORCL/redo*.log /oradata/ORCL/
###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
###it is impt to backup the database after the restore and recovery of a
critical file###
SQL> alter database begin backup;
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)
sqlplus / as sysdba
OR
SQL> ! cp /oradata/HOT_BACKUP/ORCL/control*.ctl /oradata/ORCL/
##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
OR
Clear all unarchived logfile
=================================================================================
6-database-loss ---------------------> 6b-recover-from-total-loss
remove all files in /oradata/ORCL/*.*
perform recovery on ORCL
==================================================================================
. oraenv
db_name
sqlplus / as sysdba
##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
OR
Clear all unarchived logfile
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
1) /oradata/REFRESH/(clone)
2) /u01/app/oracle/admin/REFRESH/adump (clone)
4) /oradata/FRA/REFRESH/archivelog (clone)
####it is impt to do archive log bec users where still writing to the db when u
put the db in backup mode####
C) IN WINSCP AGAIN
D) IN OPERATIING SYSTEM
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
Database altered.
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(.)
[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/
-----------------------------------------------------------------------------------
------------------------------
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
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
-----------------------------------------------------
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>>>
now since the backup you did was in inconsistent, we need recovery.
-----------------------------------------------------------------------
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)
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
. oraenv
TLSDMO
O/S> mkdir -p /oradata/TLSDMO_BACKUP
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 *****
==============================================================================
2) create a recovery catalog owner called rmanbrontech1 in your RCAT database
==============================================================================
. oraenv
RCAT
O/S> sqlplus / as sysdba
SQL> archive log list; ***check if the database is in archive log mode***
================================================================================
3) register the TLSDMO database in your recovery catalog
================================================================================
. oraenv
TLSDMO
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT
==================================================================================
5) catalog the backup made in step 1
==================================================================================
####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 /
yes
ASSIGNMENT 7
TLSDMO
==============================================================================
1) configure auto backup on
==============================================================================
. oraenv
TLSDMO
O/S> rman target /
RMAN> show all;
================================================================================
2) Configure block change tracking
=================================================================================
. oraenv
TLSDMO
ll
###Block change tracking back just the changes that toook place in the database ###
==================================================================================
3) perform a level 0 backup
==================================================================================
exit
O/S> sqlplus / as sysdba
SQL> commit;
===========================================================================
4) perform a level 1 backup
============================================================================
exit
=================================================================================
5) perform an image copy backup ( datafiles, archivelogs, spfile, controlfile) to
location /oradata/TLSDMO_IMAGE_COPY/
==================================================================================
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
===============================================================================
2) Perform a "switch datafile to copy" of the following datafiles
===============================================================================
/oradata/TLSDMO/psimgr.dbf
/oradata/TLSDMO/psindex.dbf
cd /oradata/TLSDMO
LL
O/S> rm psindex.dbf psimgr.dbf
LL
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT;
Part 2
TLSDMO
. oraenv
TLSDMO
O/S> mkdir -p /oradata/TLSDMO_COPY2/
O/S> rman target / catalog rmanbrontech/rmanbrontech@RCAT;
RMAN> exit
*.db_file_name_convert='/oradata/TLSDMO/','/oradata/CRMPRD/'
*.log_file_name_convert='/oradata/TLSDMO/','/oradata/CRMPRD/'
. oraenv
TLSDMO
sqlplus / as sysdba
SQL> startup nomount pfile = '$ORACLE_HOME/dbs/initTLSDMO2.ora';
exit
rman auxiliary /
. oraenv
TLSDMO2
O/S> sqlplus / as sysdba
SQL> select status from v$instance;
Assignment 9
==============
=================================================================================
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;
sql> create user CLASS1 identified by class1 default tablespace STUDENT quota
unlimited on STUDENT;
COUNT(*)
----------
14
COUNT(*)
----------
14
exit
RMAN> exit
Transportable tablespace
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
***removed the 4 tablespace back to read write mode =" online "***
============================================================================
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**
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;
*** putting the import tables now in online mode= read write mode***
SQL> alter tablespace pswork 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
---------------
=================================================================================
1. Row level flashback
=================================================================================
. oraenv
O/S> TLSDMO
O/S> sqlplus / as sysdba
**Setting the retention time for flashback files (in minutes) � 2 days***
SQL> commit;
CURRENT_SCN
-----------
3833131
===========================================================================
2.Flashback drop table
===========================================================================
===========================================================================
3.Flashback drop user
===========================================================================
SQL> select current_scn from v$database;
ASSIGNMENT 12
===============
Transparent Data Encryption
==============================
TLSDMO
==========================================================================
1) Create an encrypted tablespace called PEOPLETOOLS
===========================================================================
cd $ORACLE_HOME/network/admin
ll
vi sqlnet.ora
ENCRYPTION_WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=
(DIRECTORY=/oradata/wallet)))
TABLESPACE_NAME ENC
------------------------------ ---
PEOPLETOOLS YES
SQL> select tablespace_name,encrypted from dba_tablespaces;
===========================================================================
2) Copy move the table SYSADM.PSOPRDEFN to the tablespace PEOPLETOOLS
===========================================================================
SQL> alter table SYSADM.PSOPRDEFN move tablespace PEOPLETOOLS;
==========================================================================
3) Perform a datapump export of the PEOPLETOOLS tablespace
==========================================================================