Professional Documents
Culture Documents
Database Security :
------------------
The GRANT command is used for providing the authorization to the users and then
REVOKE command is used for withdrawing the authorization.
_______________________________________________________________
After creating certain username u must grant permission for login,here it shows
some permission i.e.,create session.so grant tat permission.
________________________________________________________________
Change password:
---------------
Method 1:
---------
Syntax: Alter user user_name identified by new_password.
-------
Method 2:
---------
SQL> password
old password : old_password
new password : new_password
retype password : new_password
password change
________________________________________________________________
PRIVILEGE:
----------
* Object Privileges
* System Privileges
Object Privileges:
------------------
System privileges:
------------------
##In object priv lets consider u have many table.If im giving object privilg like
insert,update,delete,then its not im grant permission to all table under db,u have
to mention to which table u have to grant permission.
________________________________________________________________
PROVIDING AUTHORIZATION:
------------------------
The GRANT command is used for providing the authorization to the users...some of
the grant commands are....
______________________________________________________________
Prevent Permissions:
--------------------
REVOKE command is used for withdrawing the authorization.
Roles:
------
Role is an object created with set of privileges and password in order to maintain
user permissions effectively.
##so u already create some role and then u grant tat role for user,
PERFORMANCE TUNING:
---------------------
Some times if you want to delete the whole table values okay..we can use truncate
instead of delete ..This is one kind of performance tuning..
________________________________________________________________
Query Analysis:
---------------
Query analysis is helps to improve overall performance of query, which will speed
up the database functions..okay...
If we are doing any query(select* from emp)it just return some o/p.then we don't
know what is happening in execution then what happening in background ..
ID NAME
---------- --------------------
1 Ragav
2 Kiru
3 nandy
4 Harsh
5 Zubair
5 Anchal
4 Ankit
7 rows selected.
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1898697977
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| DIVI | 1 | 25 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
578 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
7 rows processed
SQL>
Explanation:
-----------
So ,If we simply give autotrace on nahh..it gives all rows, and execution plan.It
show u execute select st,tat st is accessing full table and table name and total
num of rows and its statistics okay..
with this autotrace it display all rows in table then exec plan and
statistics,which i didn't want to display,if you want to see only exec plan then
use explain plan method.
________________________________________________________________
To explain a SQL statement, use the EXPLAIN PLAN FOR before the statement. For
example:
This explains the plan into the PLAN_TABLE .So The PLAN_TABLE is What is nahh
automatically created as a global temporary table to hold the output of an EXPLAIN
PLAN .
Now, You can then select the execution plan from PLAN_TABLE by using
dbms_xplan.display.
PLAN_TABLE_OUTPUT
----------------------------------------------------------------
Plan hash value: 1898697977
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| DIVI | 1 | 25 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
8 rows selected
So ,by using autotrace or explain plan we can see the performance by using time or
CPU cost okay...
Incase if you want to store all this exec plan u must have to save all this in some
files.
________________________________________________________________
(((((((((
Now Index on Performance tuning:
--------------------------------
SQL> select id,name from divi where id=1;
ID NAME
---------- --------------------
1 Ragav
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1898697977
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DIVI | 1 | 25 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
1 - filter("ID"=1)
ID NAME
---------- --------------------
1 Ragav
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1898697977
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 25 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DIVI | 1 | 25 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
1 - filter("ID"=1)
ID NAME
---------- --------------------
1 Ragav
xecution Plan
----------------------------------------------------------
Plan hash value: 2206057246
--------------------------------------------------------------------------------
----
--------------------------------------------------------------------------------
----
----------------------------------------------------------------
Can you see the performance is increasing...That First CPU cost is 4 after creating
index for column now the CPU cost is 3
Here We use small table so,If we compare the performance by using time,CPU nah.. it
remains same right..But we can see little difference...
If we have large table is not a problem we can see the difference here we using
small small tables right!.. so we can't see the as much performance improvement
here...okay....
________________________________________________________________
TRACE FILE:
-----------
A trace file is a file containing a execution status during some process
##but i don't have permission for using this trace file.i will show how to work
with this trace file and where it is located inside oracle.
##If u want to work with this u have some tools,only if u have privilege to work
with that tool then only u can see the content of tat file.
but here i cant find the name of this trace file since it is going to assign some
pseudo names..
##here we naming our file,because it hard to find which par file is having exection
file for ur table.or else it can assign name randomly.Bcoz in oracle there will be
many trace file.By using name we easily identified our trace file.
now the execution plans for this two queries will be stored in the trace file.
#trace file is very secure.is not like normal file.it stored in the route directory
of oracle.
SQL>host
[test@localhost ~]$ cd $ORACLE_BASE
cd admin/
cd XE
ls
cd udump/
ls
cat filename.trc
for this.
tkprof utility(transient kernel profiler) by this we can make trace files in a
readable form...
________________________________________________________________
Backup and recovery will protect our database against data loss and can be used to
recover the data.
A backup is like a copy of data.This copy can include important parts of the
database, such as the control file and datafiles so that we can recover the
data,when an unexpected data loss occured.
SQL>!cat backup.txt
Cold backup: It is taken when the database is closed and not available to users.
All files of the database are copied (image copy). The datafiles cannot be changed
during the backup as they are locked, so the database remains in sync upon restore.
Hot backup: While taking the backup, if the database remains open and available to
users then this kind of back up is referred to as hot backup. Image copy is made
for all the files. As, the database is in use the entire time, so