Monday, 23 May 2011

Linux referance


1.#pwd
2.#ls (files and sub dir)
3.#ls -l
4.#chmod 765 abc.txt  (r-4,w-2,x-1)
5.#chmod -r 765 /home/oracle/xyz
6.#chown antony:msc abc.txt   (antony-owner,msc-group)
7.#chown -r antony:msc /home/oracle/xyz
8.#ls -al
9.#ls -lt
10.#ls -ltr
11.#ls -lf
12.#ls -lb (display size in byts)
13.#cat>abc.txt (ctrl+d -save)
14.#more abc.txt
15.#rm -fr * (remove for the particular mount point)
16.#head -10 abc.txt
17.#cat abc.txt|tail -10
18.#head -7 abc.txt|tail -3
19.#ls -l|grep "sep"
20.#cat abc.txt|grep "mani"
21.#ls -l |egrep "(sep|nov)"
22.#ls -l |grep -v "oct"   (-v same for <>)
23.#touch xyz.txt
24.#cp abc.txt xyz.txt
25.#cp * /backup
26.#cp -r * /backup   (files and subdirectory)
27.#mv abc.txt /backup
28.#mkdir app
29.#mkdir -p /opt/oracle/..
30.#mkdir d1 d2 d3
31.#mount /dev/cdrom /mnt
32.#cd /mnt
33.#cd /  #eject  (remove disk)
34.#kill -9(or)q <pid>
35.#df -h
36.#df -m
37.#du -h oracle
38.#ps -ef
39.#ps -ef |grep pmon|wc
40.#more /etc/oratab
41.#cat /etc/oratab
42.#free -m
44.#find . -name "*.arc" -print
45.#gzip *.arc
46.#gunzip *.gz
47.#rm -fr *.arc
48.#crontab -e
49.#crontab -l
50.#crontab -r

ASM creation

ASM Creation (Windows)
You can follow this steps and create a ASM diskgroup on your local machine and play with it ( Windows)

1) Creating a dummy disks

F:\>mkdir asmdisks
F:\>cd asmdisks
F:\asmdisks>asmtool -create F:\asmdisks\ disk1 512
F:\asmdisks>asmtool -create F:\asmdisks\ disk2 512
F:\asmdisks>asmtool -create F:\asmdisks\ disk3 512

Now you have 3 disks(dummy) of 512mb each which can be used to create a ASM disk group.

2) Create ASM instance

a) Configure Cluster Synchronization Servie

C:\>c:\oracle\product\ 10.2.0\db_ 1\BIN\localconfig add

Step 1: stopping local CSS stack
Step 2: deleting OCR repository
Step 3: creating new OCR repository
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'ap\arogyaa' , privgrp ''..
Operation successful.
Step 4: creating new CSS service
successfully created local CSS service
successfully reset location of CSS setup
b) Create Init pfile
Open notepad edit the following parameters and save file as "C:\oracle\product\ 10.2.0\db_ 1\database\ init+ASM. ora"
INSTANCE_TYPE= ASM
DB_UNIQUE_NAME= +ASM
LARGE_POOL_SIZE= 8M
ASM_DISKSTRING= 'F:\asmdisks\ *'
_ASM_ALLOW_ONLY_RAW_DISKS= FALSE

c) Create service and password file
oradim will create an ASM instance and start it automatically.
c:\> orapwd file=C:\oracle\ product\10. 2.0\db_1\ database\ PWD+ASM.ora password=asm
c:\> oradim -NEW -ASMSID +ASM -STARTMODE auto

3) Create ASM disk group
a) Create asm disk group
SQL> select path, mount_status from v$asm_disk;
PATH MOUNT_S
------------ --------- --------- --
F:\ASMDISKS\ DISK1 CLOSED
F:\ASMDISKS\ DISK3 CLOSED
F:\ASMDISKS\ DISK2 CLOSED

SQL> create diskgroup data external redundancy disk
2 'F:\ASMDISKS\ DISK1',
3 'F:\ASMDISKS\ DISK2',
4* 'F:\ASMDISKS\ DISK3';
Diskgroup created.
b) Change PFILE to SPFILE, Add ASM Diskgroup parameter and your all set to go and use ASM.
SQL> create spfile from pfile;
SQL> startup force;
SQL> alter system set asm_diskgroups= data scope=spfile;
SQL> startup force;
SQL> startup force
ASM instance started
Total System Global Area 83886080 bytes
Fixed Size 1247420 bytes
Variable Size 57472836 bytes
ASM Cache 25165824 bytes
ASM diskgroups mounted
SQL>
Now you can go ahead and use your DBCA and create a database and on step 6 of 13, you can use Automatic Storage management as your Filesystem.



---------------------------------------------------------------------------
SQL> create spfile from pfile='D:\oracle\product\10.2.0\db_1\database\init+ASM.ora';
File created.
SQL> startup nomount
ASM instance started
Total System Global Area   79691776 bytes
Fixed Size                  1247396 bytes
Variable Size              53278556 bytes
ASM Cache                  25165824 bytes
SQL> alter system set ASM_diskgroups=data scope=spfile;

System altered.
SQL> shut immediate
ORA-15100: invalid or missing diskgroup name
ASM instance shutdown
SQL> startup
ASM instance started
Total System Global Area   79691776 bytes
Fixed Size                  1247396 bytes
Variable Size              53278556 bytes
ASM Cache                  25165824 bytes
ASM diskgroups mounted
SQL>





AWR/ADDM/Statspack referance


Statspack report:
Sql>@? /rdbms/admin/spdrop.sql
Sql>@? /rdbms/admin/spcreate.sql
Snapshot catch
Sql> exec statspack.snap
Sql> exec statspack.snap
Sql>@? /rdbms/admin/spreport.sql
sql>@? /rdbms/admin/spauto.sql
AWR:
Sql>alter system set statistics_level = typical/all;
Change the interval/retention period
Sql>exec dbms_workload_repository.modify_snapshot_settings (retention =>43200,interval =>30); (30*24*60 = 43200 30=days,24 = hrs , 60 = minutes)
Sql>exec dbms_workload_repository.create_snapshot;
Sql>select * from dba_hist_snapshot;(display all snapshot)
Sql>select * from dba_hist_wr_contrl;
Sql>@? /rdbms/admin/awrrpt.sql
Sql>select snap_id from dba_hist_snapshot;
ADDM
Sql>@? /rdbms/admin/addmrpt.sql

Standby-pfile(two)

##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################

###########################################
# Cache and I\O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16

###########################################
# Cursors and Library Cache
###########################################
open_cursors=300

###########################################
# Database Identification
###########################################
db_domain=""
*.audit_file_dest='G:\oracle\product\10.2.0\admin\two\adump'
*.background_dump_dest='G:\oracle\product\10.2.0\admin\two\bdump'
*.core_dump_dest='G:\oracle\product\10.2.0\admin\two\cdump'
*.user_dump_dest='G:\oracle\product\10.2.0\admin\two\udump'
*.compatible='10.2.0.1.0'
control_files='G:\ORACLE\PRODUCT\10.2.0\ORADATA\two\STAN.CTL','G:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\two\STAN.CTL'
db_name='one'
db_unique_name=two
LOG_ARCHIVE_CONFIG='DG_CONFIG=(one,two)'
LOG_ARCHIVE_DEST_1=
'LOCATION=G:\oracle\product\10.2.0\flash_recovery_area\TWO\ONLINELOG
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=two'
LOG_ARCHIVE_DEST_2=
'SERVICE=one LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=one'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
FAL_SERVER=one
FAL_CLIENT=two
remote_login_passwordfile='EXCLUSIVE'
# Specify the location of the primary DB datafiles followed by the standby location
DB_FILE_NAME_CONVERT='G:\oracle\product\10.2.0\oradata\one\','G:\oracle\product\10.2.0\oradata\two\'
# Specify the location of the primary DB online redo log files followed by the standby location
LOG_FILE_NAME_CONVERT='G:\oracle\product\10.2.0\oradata\one\','G:\oracle\product\10.2.0\oradata\two\','G:\Oracle\product\10.2.0\flash_recovery_area\one\','G:\Oracle\product\10.2.0\flash_recovery_area\two\'
STANDBY_FILE_MANAGEMENT=AUTO

###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=G:\oracle\product\10.2.0\admin\two\bdump
core_dump_dest=G:\oracle\product\10.2.0\admin\two\cdump
user_dump_dest=G:\oracle\product\10.2.0\admin\two\udump

###########################################
# File Configuration
###########################################

db_recovery_file_dest=G:\oracle\product\10.2.0\flash_recovery_area
db_recovery_file_dest_size=2147483648
db_file_name_convert=("G:\oracle\product\10.2.0\oradata\one","G:\oracle\product\10.2.0\oradata\two")
log_file_name_convert=("G:\oracle\product\10.2.0\oradata\one","G:\oracle\product\10.2.0\oradata\two")
###########################################
# Job Queues
###########################################
job_queue_processes=10

###########################################
# Miscellaneous
###########################################
compatible=10.2.0.1.0

###########################################
# Processes and Sessions
###########################################
processes=150

###########################################
# SGA Memory
###########################################
sga_target=570425344

###########################################
# Security and Auditing
###########################################
audit_file_dest=G:\oracle\product\10.2.0\admin\two\adump
remote_login_passwordfile=EXCLUSIVE

###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=twoXDB)"

###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=189792256

###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1

Standby-pfile(one)

##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################

###########################################
# Cache and I\O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16

###########################################
# Cursors and Library Cache
###########################################
open_cursors=300

###########################################
# Database Identification
###########################################
db_name=one
db_unique_name=one
LOG_ARCHIVE_CONFIG='DG_CONFIG=(one,two)'
LOG_ARCHIVE_DEST_1=
'LOCATION=G:\oracle\product\10.2.0\flash_recovery_area\ONE\ONLINELOG
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=one'
LOG_ARCHIVE_DEST_2=
'SERVICE=two LGWR ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=two'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
remote_login_passwordfile='EXCLUSIVE'
FAL_SERVER=two
FAL_CLIENT=one
STANDBY_FILE_MANAGEMENT=AUTO
# Specify the location of the standby DB datafiles followed by the oneary location;
DB_FILE_NAME_CONVERT='G:\oracle\product\10.2.0\oradata\two\','G:\oracle\product\10.2.0\oradata\one\'
# Specify the location of the standby DB online redo log files followed by the oneary location
LOG_FILE_NAME_CONVERT='G:\oracle\product\10.2.0\oradata\two\','G:\oracle\product\10.2.0\oradata\one\','G:\Oracle\flash_recovery_area\two\ONLINELOG','G:\Oracle\flash_recovery_area\one\ONLINELOG'

###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=G:\oracle\product\10.2.0\admin\one\bdump
core_dump_dest=G:\oracle\product\10.2.0\admin\one\cdump
user_dump_dest=G:\oracle\product\10.2.0\admin\one\udump

###########################################
# File Configuration
###########################################
control_files=("G:\oracle\product\10.2.0\oradata\one\control01.ctl", "G:\oracle\product\10.2.0\oradata\one\control02.ctl", "G:\oracle\product\10.2.0\oradata\one\control03.ctl")
db_recovery_file_dest=G:\oracle\product\10.2.0\flash_recovery_area
db_recovery_file_dest_size=2147483648

###########################################
# Job Queues
###########################################
job_queue_processes=10

###########################################
# Miscellaneous
###########################################
compatible=10.2.0.1.0

###########################################
# Processes and Sessions
###########################################
processes=150

###########################################
# SGA Memory
###########################################
sga_target=570425344

###########################################
# Security and Auditing
###########################################
audit_file_dest=G:\oracle\product\10.2.0\admin\one\adump
remote_login_passwordfile=EXCLUSIVE

###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=oneXDB)"

###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=189792256

###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
 

RMAN referance



RMAN
BackUp
$export ORACLE_SID = Test
$rman target /
Rman >backup database;
Rman >backup tablespace data,users;
Rman >backup datafile 10,12;
Rman>backup current control file;
Rman>backup archivelog all;
Rman>backup archivelog all delete input;
Rman>backup spfile;
Rman>backup archivelog until ‘sysdate – 1’ delete input;
Rman>backup archivelog skip inaccessible;

RECOVERY

\
Rman>sql ’alter database datafile 10 offline drop;
Rman>restore datafile 10 ;
Rman>recover datafile 10;
Rman>sql ‘ alter database datafile 10 online’;
/


\

Rman>run {
sql ’alter database datafile 10 offline drop;
restore datafile 10 ;
recover datafile 10;
sql ‘ alter database datafile 10 online’;
}
/
Recover tablespace
\
Rman >run  {
Sql ‘alter tablespace data offline’;
Restore tablespace data;
Recover tablespace data;
Sql ‘alter tablespace data online’;
}
/
Read only Tablespace corrupted (recover)
\
Rman>run {
Sql ‘alter tablespace data offline’;
Restore tablespace data;
Sql ‘alter tablespace data online’;
}
/

System/Undo/ Tablespace corrupted (recover)
\
Startup mount
Rman> run {
Restore tablespace system;
Recover database;
Open database;
}
/
Database corrupted (recover)
\
Startup mount
Rman> run {
Restore database;
Recover database;
Open database;
}
/

Catalog Database
/
$ export ORACLE_SID = apps
sql>create tablespace rmanths datafile ‘/opt /oracle/rman 01.dbf’ size 100m;
sql>create user rman identified by rman default tablespace rmanths temporary tablespace temp;
sql> grant connect ,resource to rman;
sql>grant recovery_catalog_owner to rman;
 $ export ORACLE_SID = test
$ rman target / catalog  rman/rman@apps123
Rman>create catalog ;
Rman>register database;
Rman>backup database plus archivelog include current control file;
Rman>resync database; or rman>resync catalog;

Control file recovery
$ export ORACLE_SID = test
Rman>restore controlfile from ‘/opt/oracle/aXX ‘ ;
Rman>alter database mount ;
Rman>recover database ;
Rman>open database;
Control file recovery  (Catalog database )
Startup no mount
$ export ORACLE_SID = test
$ rman target / catalog rman/rman@apps123
Rman> restore controlfile;
Rman> alter database mount;
Rman> recover database;
Rman> open database;

Incremental Backup
Rman> backup database; (level 0 backup)
Rman> backup incremental level 1 database;
Rman> backup incremental level 1 cumulative database;
RMAN Script
Rman> create script level1db
{
Backup incremental level 1 database;
Backup archivelog all delete input;
Backup current control file;
Backup spfile;
}
Rman> run { execute script level1db;}
Rman> print level1db;( display script content)
Rman> delete level1db;
SCN based (recover) database:

Rman > run {
Set until SCN ‘137’;
Retore database;
Recover database;
Open resetlogs database;
}
TIME based (recover) database:

Rman > run {
Set until TIME =  ‘DD-MM-YY HH24:MI:SS’;
Retore database;
Recover database;
Open resetlogs database;
}

Log sequence based (recover) database:

Rman > run {
Set until log seq 1313 thread 1;
Retore database;
Recover database;
Open resetlogs database;
}
Restore in different location
Rman > run {
set until logseq 1313 thread 1;
set newname for datafile 1 to ‘ /U01/oracle/system01.dbf’;
set newname for datafile 2 to ‘ /U01/oracle/undo.dbf’;
set newname for datafile 3 to ‘ /U01/oracle/sysaux.dbf’;
set newname for datafile 4 to ‘ /U01/oracle/users.dbf’;
retore database;
switch datafile all;
recover database;
open resetlogs database;
}
Backup Options
Rman>backup database format ‘ /backup/rman_%d_%s_%p_%u’;
Maxset size:
Rman>backup database maxsetsize = 100m;
MAXpicesize
Rman>backup database maxpicesize = 100m;
Fileperset
Rman>backup database fileperset = 3;
Rate:
Rman>backup database rate 1m; ( 1mb data will be retrieved from 1 second)
Backup set identification:
Rman> backup database tag =’full_backup_412’;
Rman>restore database from tag ’full_backup_412’;
RMAN configuration:
Rman> Show all;
Rman> configuration retention policy to redundancy 3;
Rman> configuration retention policy to recovery window of 10 days;
Rman> report obsolete;(check whether retention (of 3 backup or 10 days backup ))
Rman> delete obsolete ;
Rman > report need backup;
Rman> configure default device type to disk;
Rman> configure default device type to ‘sbt’;
Rman> allocate channel for maintenance type disk (or) ‘sbt’;
Rman>configure channel device type disk format '/oracle/rman_bk/rmanbk_bk_%d_%u_%s_%p';
\
Rman>configure device type disk parallelism 5; (allocating channels)
 Example:
Rman> run {
Allocate channel c1 type disk format ‘/opt/rman_%u;
Allocate channel c2 type disk format ‘/u2/rman_%u;
Allocate channel c3 type disk format ‘/u3/rman_%u;
Backup database;
Release channel c1;
Release channel c2;
Release channel c3;
}
/
Rman>configure controlfile autobackup on;
Rman>configure controlfile autobackup format for device type disk to ‘/backup/control_%f’;
Rman>configure device type disk backup type to backupset;
Rman>configure device type backup type to copy;(image copy backup)
Rman>configure device type backup type to compressed backupset;
Rman>comfigure backup optimization on; (only once take archive log)
Rman>configure for exclude tablespace users; (not take backup for users)
Rman> select * from v$ tablespace;
Output;  name = users , Inc (include) = no
Rman> backup database noexclude;
Rman>configure for exclude tablespace users clear;
Rman>backup database skip offline skip read only;
Rman>backup archivelog all skip inaccessible;
Rman>validate backup database;(Wont take backup only verify it)
Rman>validate restore database;
Rman>list backup of database;
Rman>crosscheck backup;(check corrupted or proper)
Rman> crosscheck backup of database;
Rman>delete expired backup;
Block change tracking
Sql>alter database enable block change tracking using file ‘/opt/bcff.chg’;
Block recover
Rman>block recover datafile 10 block 121;
Rman>run{
Set maxcorrupt =3;
Backup database;
}
check only catalog users
\
Sql>conn rman/rman;
Sql>select * from rc_backup_datafile;
Sql>select * from rc_backup_redolog;
Sql>select * from rc_backup_spfile;
Sql>select * from rc_controlfile_copy;
Sql>select * from rc_backup_block_corruption;
Sql>select * from rc_resync;
Sql>select * from re_rman_configuration;
Sql> select * from rc_stored_script;
Sql>select * from rc_stored_script_line;

Sunday, 22 May 2011

Flash Back Technologies



Flash Back Technologies
Sql>show parameter db_recovery_file_dest;
Rman>backup db_recovery_file_dest;
Sql>show parameter db_recovery_file_dest_size;
Sql>alter system set_db_recovery_file_dest_size=10G;
Flashback Enable
/*
Sql>startup mount
Sql>alter database archievelog;
Sql>alter database flashback on;
Sql>alter database open;

Sql>select flashback_on from v$database;
o/p : yes à enable ; no à disable
*/
Flashback database
/*
Example
Sql>create table product (product number(10));
 insert à 100 records
sql> commit;
sql>select current_timestamp from dual;
o/p: display the current time stamp
sql> select current_scn from v$database;
o/p: display the current scn
sql> drop table product ;
sql> create table dept (dno number (10));
sql> insert 100 record;
sql> commit;
sql> shutdown immediate;
sql>startup mount;
sql> flashback database to timestamp to_data (09-JUN-10  12:15:40);
sql> flashback database to scn ‘11123’;
sql> flashback database to logseq 1002 thread 1;
sql> alter database open resetlogs;
*/
sql> alter tablespace users flashback off;
sql> alter tablespace users flashback on;
sql > select  name , flashback  from v$tablsepace;
o/p : yes à enable ; no à disable

Flashback Drop:
Sql> show recycle bin;
                or
Sql > select * from dba_recyclebin
                Or
Sql > select * from user_recyclebin;

Example
Sql > drop table product;
Sql > flashback table product to before drop;
Sql > flashback table product to before drop rename to product1;
Permanent Drop
Sql > drop table product purge ;
                Or
Sql > purge table product;
Sql> purge tablespace users;
Sql> purge tablespace data user mathan;
Sql > drop tablespace data;
Sql > drop user mathan;
Tablespace data & user mathan wont store in recyclebin
Flashback Query :
Sql>create table  product (product number (10));
Sql > insert “200” record;
Sql>commit;
Sql>select current_timestamp from dual;
Sql> select current_scn from v$database;
Sql> delete from product;
Sql> commit;
Sql> select * product as of timestamp to_timestamp ( ’90-11-2009. 12:15:45………’);
Sql> select * from product as of scn ‘556790’;
Sql> select * from product;
Move to another table:
Sql>create table product1 as select * from product as of scn ‘556790’;
Flashback Version Query:
It is used to find the transactions happened in the table.
Ex :
Sql> create table product (pno  number(10) );
Sql> insert record  values 1 to  100;
Sql>commit;
Sql> select current_scn from v$database;
o/p: 1000
sql>insert into product values (101);
sql>update product set pno = 1000 where pno = 100;
sql>delete from product where pno = 101;
sql> commit;
sql>select current_scn from v$database;
o/p: 1100
sql> select version_xid, versions_operation ,pno from product version between scn 1000 and 1100;
o/p:
VXID         VO          pno
X111      I               200
X112      U             1000
X113      D             202
 I à insert ; Uà update ; D à delete

Flashback Transaction Query
It is used to find out which query it has been executed.
Sql>select undo_sql from flashback_transaction_query where xid = ‘x112’;
o/p :  update product set pno = 1000 where pno = 100;
Flashback table :
We can use flashback table for scn, time .
Sql> create table product (pno number (10));
Sql > insert 100;
Sql > commit;
Sql> select current_scn from v$database;
o/p: 1000
sql> delete from product;
sql > commit;
sql> insert 101;
sql> commit;
sql> alter table product  enable row movement;
sql> flashback table product to scn 1000;
sql> select * from product;
o/p: 100

Saturday, 21 May 2011

Auditing

Auditing in Oracle 10g Release 2

This article presents an overview of auditing in Oracle 10g Release 2. Many of the topics presented here have been covered in previous articles, but this serves to bring them all together.
Related articles.

Server Setup

Auditing is a default feature of the Oracle server. The initialization parameters that influence its behaviour can be displayed using the SHOW PARAMETER SQL*Plus command.
SQL> SHOW PARAMETER AUDIT

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest                      string      C:\ORACLE\PRODUCT\10.2.0\ADMIN
                                                 \DB10G\ADUMP
audit_sys_operations                 boolean     FALSE
audit_trail                          string      NONE
SQL>
Auditing is disabled by default, but can enabled by setting the AUDIT_TRAIL static parameter, which has the following allowed values.
AUDIT_TRAIL = { none | os | db | db,extended | xml | xml,extended }
The following list provides a description of each setting:
  • none or false - Auditing is disabled.
  • db or true - Auditing is enabled, with all audit records stored in the database audit trial (SYS.AUD$).
  • db,extended - As db, but the SQL_BIND and SQL_TEXT columns are also populated.
  • xml- Auditing is enabled, with all audit records stored as XML format OS files.
  • xml,extended - As xml, but the SQL_BIND and SQL_TEXT columns are also populated.
  • os- Auditing is enabled, with all audit records directed to the operating system's audit trail.
Note. In Oracle 10g Release 1, db_extended was used in place of db,extended. The XML options are new to Oracle 10g Release 2.

The AUDIT_SYS_OPERATIONS static parameter enables or disables the auditing of operations issued by users connecting with SYSDBA or SYSOPER privileges, including the SYS user. All audit records are written to the OS audit trail.

The AUDIT_FILE_DEST parameter specifies the OS directory used for the audit trail when the os, xml and xml,extended options are used. It is also the location for all mandatory auditing specified by the AUDIT_SYS_OPERATIONS parameter.

To enable auditing and direct audit records to the database audit trail, we would do the following.
SQL> ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE;

System altered.

SQL> SHUTDOWN
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP
ORACLE instance started.

Total System Global Area  289406976 bytes
Fixed Size                  1248600 bytes
Variable Size              71303848 bytes
Database Buffers          213909504 bytes
Redo Buffers                2945024 bytes
Database mounted.
Database opened.
SQL>

Audit Options

One look at the AUDIT command syntax should give you an idea of how flexible Oracle auditing is. There is no point repeating all this information, so instead we will look at a simple example.

First we create a new user called AUDIT_TEST.
CONNECT sys/password AS SYSDBA

CREATE USER audit_test IDENTIFIED BY password
  DEFAULT TABLESPACE users
  TEMPORARY TABLESPACE temp
  QUOTA UNLIMITED ON users;

GRANT connect TO audit_test;
GRANT create table, create procedure TO audit_test;
Next we audit all operations by the AUDIT_TEST user.
CONNECT sys/password AS SYSDBA

AUDIT ALL BY audit_test BY ACCESS;
AUDIT SELECT TABLE, UPDATE TABLE, INSERT TABLE, DELETE TABLE BY audit_test BY ACCESS;
AUDIT EXECUTE PROCEDURE BY audit_test BY ACCESS;
These options audit all DDL and DML, along with some system events.
  • DDL (CREATE, ALTER & DROP of objects)
  • DML (INSERT UPDATE, DELETE, SELECT, EXECUTE).
  • SYSTEM EVENTS (LOGON, LOGOFF etc.)
Next, we perform some operations that will be audited.
CONN audit_test/password

CREATE TABLE test_tab (
  id  NUMBER
);

INSERT INTO test_tab (id) VALUES (1);
UPDATE test_tab SET id = id;
SELECT * FROM test_tab;
DELETE FROM test_tab;

DROP TABLE test_tab;
In the next section we will look at how we view the contents of the audit trail.

View Audit Trail

The audit trail is stored in the SYS.AUD$ table. Its contents can be viewed directly or via the following views:
SELECT view_name
FROM   dba_views
WHERE  view_name LIKE 'DBA%AUDIT%'
ORDER BY view_name;

VIEW_NAME
------------------------------
DBA_AUDIT_EXISTS
DBA_AUDIT_OBJECT
DBA_AUDIT_POLICIES
DBA_AUDIT_POLICY_COLUMNS
DBA_AUDIT_SESSION
DBA_AUDIT_STATEMENT
DBA_AUDIT_TRAIL
DBA_COMMON_AUDIT_TRAIL
DBA_FGA_AUDIT_TRAIL
DBA_OBJ_AUDIT_OPTS
DBA_PRIV_AUDIT_OPTS
DBA_REPAUDIT_ATTRIBUTE
DBA_REPAUDIT_COLUMN
DBA_STMT_AUDIT_OPTS

14 rows selected.

SQL>
The three main views are:
  • DBA_AUDIT_TRAIL - Standard auditing only (from AUD$).
  • DBA_FGA_AUDIT_TRAIL - Fine-grained auditing only (from FGA_LOG$).
  • DBA_COMMON_AUDIT_TRAIL - Both standard and fine-grained auditing.
The most basic view of the database audit trail is provided by the DBA_AUDIT_TRAIL view, which contains a wide variety of information. The following query displays the some of the information from the database audit trail.
COLUMN username FORMAT A10
COLUMN owner    FORMAT A10
COLUMN obj_name FORMAT A10
COLUMN extended_timestamp FORMAT A35

SELECT username,
       extended_timestamp,
       owner,
       obj_name,
       action_name
FROM   dba_audit_trail
WHERE  owner = 'AUDIT_TEST'
ORDER BY timestamp;

USERNAME   EXTENDED_TIMESTAMP                  OWNER      OBJ_NAME   ACTION_NAME
---------- ----------------------------------- ---------- ---------- ----------------------------
AUDIT_TEST 16-FEB-2006 14:16:55.435000 +00:00  AUDIT_TEST TEST_TAB   CREATE TABLE
AUDIT_TEST 16-FEB-2006 14:16:55.514000 +00:00  AUDIT_TEST TEST_TAB   INSERT
AUDIT_TEST 16-FEB-2006 14:16:55.545000 +00:00  AUDIT_TEST TEST_TAB   UPDATE
AUDIT_TEST 16-FEB-2006 14:16:55.592000 +00:00  AUDIT_TEST TEST_TAB   SELECT
AUDIT_TEST 16-FEB-2006 14:16:55.670000 +00:00  AUDIT_TEST TEST_TAB   DELETE
AUDIT_TEST 16-FEB-2006 14:17:00.045000 +00:00  AUDIT_TEST TEST_TAB   DROP TABLE

6 rows selected.

SQL>
When the audit trail is directed to an XML format OS file, it can be read using a text editor or via the V$XML_AUDIT_TRAIL view, which contains similar information to the DBA_AUDIT_TRAIL view.
COLUMN db_user       FORMAT A10
COLUMN object_schema FORMAT A10
COLUMN object_name   FORMAT A10
COLUMN extended_timestamp FORMAT A35

SELECT db_user,
       extended_timestamp,
       object_schema,
       object_name,
       action
FROM   v$xml_audit_trail
WHERE  object_schema = 'AUDIT_TEST'
ORDER BY extended_timestamp;

DB_USER    EXTENDED_TIMESTAMP                  OBJECT_SCH OBJECT_NAM     ACTION
---------- ----------------------------------- ---------- ---------- ----------
AUDIT_TEST 16-FEB-2006 14:14:33.417000 +00:00  AUDIT_TEST TEST_TAB            1
AUDIT_TEST 16-FEB-2006 14:14:33.464000 +00:00  AUDIT_TEST TEST_TAB            2
AUDIT_TEST 16-FEB-2006 14:14:33.511000 +00:00  AUDIT_TEST TEST_TAB            6
AUDIT_TEST 16-FEB-2006 14:14:33.542000 +00:00  AUDIT_TEST TEST_TAB            3
AUDIT_TEST 16-FEB-2006 14:14:33.605000 +00:00  AUDIT_TEST TEST_TAB            7
AUDIT_TEST 16-FEB-2006 14:14:34.917000 +00:00  AUDIT_TEST TEST_TAB           12

6 rows selected.

SQL>
Several fields were added to both the standard and fine-grained audit trails in Oracle 10g, including:
  • EXTENDED_TIMESTAMP - A more precise value than the exising TIMESTAMP column.
  • PROXY_SESSIONID - Proxy session serial number when an enterprise user is logging in via the proxy method.
  • GLOBAL_UID - Global Universal Identifier for an enterprise user.
  • INSTANCE_NUMBER - The INSTANCE_NUMBER value from the actioning instance.
  • OS_PROCESS - Operating system process id for the oracle process.
  • TRANSACTIONID - Transaction identifier for the audited transaction. This column can be used to join to the XID column on the FLASHBACK_TRANSACTION_QUERY view.
  • SCN - System change number of the query. This column can be used in flashback queries.
  • SQL_BIND - The values of any bind variables if any.
  • SQL_TEXT - The SQL statement that initiated the audit action.
The SQL_BIND and SQL_TEXT columns are only populated when the AUDIT_TRAIL parameter is set to db,extended or xml,extended.

Maintenance and Security

Auditing should be planned carefully to control the quantity of audit information. Only audit specific operations or objects of interest. Over time you can refine the level of auditing to match your requirements.

The database audit trail must be deleted, or archived, on a regular basis to prevent the SYS.AUD$ table growing to an unnacceptable size.Only DBAs should have maintenance access to the audit trail. Auditing modifications of the data in the audit trail itself can be achieved using the following statement:
AUDIT INSERT, UPDATE, DELETE ON sys.aud$ BY ACCESS;
The OS and XML audit trails are managed through the OS. These files should be secured at the OS level by assigning the correct file permissions.

Fine Grained Auditing (FGA)

Fine grained auditing extends Oracle standard auditing capabilities by allowing the user to audit actions based on user-defined predicates. It is independant of the AUDIT_TRAIL parameter setting and all audit records are stored in the FGA_LOG$ table, rather than the AUD$ table. The following example illustrates how fine grained auditing is used.

First, create a test table.
CONN audit_test/password

CREATE TABLE emp (
 empno     NUMBER(4) NOT NULL,
 ename     VARCHAR2(10),
 job       VARCHAR2(9),
 mgr       NUMBER(4),
 hiredate  DATE,
 sal       NUMBER(7,2),
 comm      NUMBER(7,2),
 deptno    NUMBER(2)
);

INSERT INTO emp (empno, ename, sal) VALUES (9999, 'Tim', 1);
INSERT INTO emp (empno, ename, sal) VALUES (9999, 'Larry', 50001);
COMMIT;
The following policy audits any queries of salaries greater than £50,000.
CONN sys/password AS sysdba

BEGIN
  DBMS_FGA.add_policy(
    object_schema   => 'AUDIT_TEST',
    object_name     => 'EMP',
    policy_name     => 'SALARY_CHK_AUDIT',
    audit_condition => 'SAL > 50000',
    audit_column    => 'SAL');
END;
/
Querying both employees proves the auditing policy works as expected.
CONN audit_test/password
SELECT sal FROM emp WHERE ename = 'Tim';
SELECT sal FROM emp WHERE ename = 'Larry';

CONN sys/password AS SYSDBA
SELECT sql_text
FROM   dba_fga_audit_trail;

SQL_TEXT
------------------------------------------
SELECT sal FROM emp WHERE ename = 'Larry'

1 row selected.

SQL>
Extra processing can be associated with an FGA event by defining a database procedure and associating this to the audit event. The following example assumes the FIRE_CLERK procedure has been defined:
BEGIN
  DBMS_FGA.add_policy(
    object_schema   => 'AUDIT_TEST',
    object_name     => 'EMP',
    policy_name     => 'SALARY_CHK_AUDIT',
    audit_condition => 'SAL > 50000',
    audit_column    => 'SAL',
    handler_schema  => 'AUDIT_TEST',
    handler_module  => 'FIRE_CLERK',
    enable          => TRUE);
END;
/
The DBMS_FGA package contains the following procedures:
  • ADD_POLICY
  • DROP_POLICY
  • ENABLE_POLICY
  • DISABLE_POLICY
In Oracle9i fine grained auditing was limited queries, but in Oracle 10g it has been extended to include DML statements, as shown by the following example.
-- Clear down the audit trail.
CONN sys/password AS SYSDBA
TRUNCATE TABLE fga_log$;
SELECT sql_text FROM dba_fga_audit_trail;

no rows selected.

-- Apply the policy to the SAL column of the EMP table.
BEGIN
  DBMS_FGA.add_policy(
    object_schema   => 'AUDIT_TEST',
    object_name     => 'EMP',
    policy_name     => 'SAL_AUDIT',
    audit_condition => NULL, -- Equivalent to TRUE
    audit_column    => 'SAL',
    statement_types => 'SELECT,INSERT,UPDATE,DELETE');
END;
/

-- Test the auditing.
CONN audit_test/password
SELECT * FROM emp WHERE empno = 9998;
INSERT INTO emp (empno, ename, sal) VALUES (9998, 'Bill', 1);
UPDATE emp SET sal = 10 WHERE empno = 9998;
DELETE emp WHERE empno = 9998;
ROLLBACK;

-- Check the audit trail.
CONN sys/password AS SYSDBA
SELECT sql_text FROM dba_fga_audit_trail;

SQL_TEXT
--------------------------------------
SELECT * FROM emp WHERE empno = 9998
INSERT INTO emp (empno, ename, sal) VALUES (9998, 'Bill', 1)
UPDATE emp SET sal = 10 WHERE empno = 9998
DELETE emp WHERE empno = 9998

4 rows selected.

-- Drop the policy.
CONN sys/password AS SYSDBA
BEGIN
  DBMS_FGA.drop_policy(
    object_schema   => 'AUDIT_TEST',
    object_name     => 'EMP',
    policy_name     => 'SAL_AUDIT');
END;
/

Friday, 20 May 2011

Hidden Parameters

SELECT X.KSPPINM NAME, DECODE(BITAND(KSPPIFLG/256, 1), 1, 'TRUE', 'FALSE') SESMOD, DECODE( BITAND(KSPPIFLG/65536, 3), 1, 'IMMEDIATE', 2, 'DEFERRED', 3, 'IMMEDIATE', 'FALSE' ) SYSMOD, KSPPDESC DESCRIPTION FROM SYS.X_$KSPPI X WHERE X.INST_ID = USERENV('INSTANCE') AND TRANSLATE(KSPPINM,'_','#') LIKE '#%' ORDER BY 1 ;

Thursday, 19 May 2011

one database more than one listener

Its easy enough. Just do something like this:

LISTENER_KRB11G =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
(ADDRESS = (PROTOCOL = TCP)(HOST = krbrhel)(PORT = 1522))
)
)
SID_LIST_LISTENER_KRB11G=
( SID_LIST =
( SID_DESC =
( GLOBAL_DBNAME = krb11g )
( ORACLE_HOME = /u01/app/oracle/product/11.1.0/db_1 )
( SID_NAME = krb11g )
)
)


KRB11G2_LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = krbrhel)(PORT = 1523))
)
)
SID_LIST_KRB11G2_LISTENER =
( SID_LIST =
( SID_DESC =
( GLOBAL_DBNAME = krb11g )
( ORACLE_HOME = /u01/app/oracle/product/11.1.0/db_1 )
( SID_NAME = krb11g )
)
)

to get status:

lsnrctl status krb11g2_listener

to start:
lsnrctl start krb11g2_listener

Wednesday, 18 May 2011

RMAN Recover

Full DR recovery - Full Example (restoring to a different machine)
Point in time recovery - Full Example (restoring to the same machine / different date/time)

Restore and recover the whole Database:
RMAN> STARTUP FORCE MOUNT;
 RMAN> RESTORE DATABASE;
 RMAN> RECOVER DATABASE;
 RMAN> ALTER DATABASE OPEN;
Restore and recover a Tablespace:
RMAN> SQL 'ALTER TABLESPACE users OFFLINE';
 RMAN> RESTORE TABLESPACE users;
 RMAN> RECOVER TABLESPACE users;
 RMAN> SQL 'ALTER TABLESPACE users ONLINE';
Restore and recover a Datafile:
RMAN> SQL 'ALTER DATABASE DATAFILE 64 OFFLINE';
 RMAN> RESTORE DATAFILE 64;
 RMAN> RECOVER DATAFILE 64;
 RMAN> SQL 'ALTER DATABASE DATAFILE 64 ONLINE';
Restore the Control file, (to all locations specified in the parameter file) then restore the database, using that control file:
STARTUP NOMOUNT;
RUN
{
ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;
RESTORE DATABASE;
}
Restore Validation confirms that a restore could be run, by confirming that all database files exist and are free of physical and logical corruption, this does not generate any output.
Example:
RMAN> RESTORE DATABASE VALIDATE;

Tuesday, 17 May 2011

Manual upgrade from 9i to 10g Release 2/DBUA

Manual upgrade from 9i to 10g Release 2

This procedure describes the steps necessary to manually upgrade a database from 9.2.x to 10.2.x. It assumes that you have already installed 10g onto the server. Of course, it is essential that you take a backup of your database before attempting any upgrade.

  • 1. Compile any invalid objects
@?/rdbms/admin/utlrp.sql
  • 2. Create a sysaux tablespace
Having a sysaux tablespace is a requirement in 10g. So, if you haven't already got one, create one now.
create tablespace sysaux
datafile '<file_name>' size 512M
extent management local
segment space management auto
/
  • 3. Run utlu102i.sql
This utility script checks that the database is ready to be upgraded to 10g. It also identifies any actions that need to be taken. The script is located in the 10g oracle home, so you will need to specify the full path to it.
@/u01/app/oracle/product/10.2.0/db_1/rdbms/admin/utlu102i.sql
Review the output and make any necessary alterations. Make a note of how many invalid objects there are.

  • 4. Shut the database down with either normal or immediate
shutdown immediate
  • 5. Copy the spfile (or pfile) and the password file from the existing home to the 10g one.
cp ${ORACLE_HOME}/dbs/*${ORACLE_SID}* <new_home>/dbs/
  • 6. Edit oratab
Alter /etc/oratab (or /var/opt/oracle/oratab) to point to the10g home. Once done, rerun oraenv to bring the alteration into effect.

  • 7. Upgrade the database
sqlplus "/ as sysdba"

startup upgrade
This next bit is the upgrade itself. It takes roughly half an hour to complete. Spool the output to a file so that you can review it afterward.
@?/rdbms/admin/catupgrd.sql
  • 8. Recompile any invalid objects
@?/rdbms/admin/utlrp.sql
Compare the number of invalid objects with the number noted in step 3. It should hopefully be the same or less.

  • 9. Then check the status of the upgrade
@?/rdbms/admin/utlu102s.sql
  • 10. Alter or remove initialisation parameters
Temporarily creating a pfile is the easiest way.
create pfile from spfile;

shutdown immediate

vi ${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
Alter/remove parameters identified in step 9. Set compatible to 10.2.0.0.0
startup

create spfile from pfile;

shutdown immediate

startup
That's it!




Upgrade Oracle 10g Release 2 from 10201 to 10204

Posted by Zahid on July 3, 2010.
This post demonstrate a step by step guide to apply oracle patchset 10.2.0.4 (patch number 6810189) on 10.2.0.1 database. My current environment is Oracle 10gR2 (10.2.0.1) installed on Redhat Enterprise Linux 5 update 4 32-bit.

Preparing for the upgrade to 10.2.0.4

Stop all oracle components running like LISTENER, EM , ISQLPLUS and DB itself etc.
/* Stop the isqlplus if running */
$ isqlplusctl stop
iSQL*Plus 10.2.0.1.0
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Stopping iSQL*Plus ...
iSQL*Plus stopped.

/* Stop the EM dbconsole */

$ emctl stop dbconsole
TZ set to US/Eastern
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0  
Copyright (c) 1996, 2005 Oracle Corporation.  All rights reserved.
http://ora10.home.com:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control ... 
 ...  Stopped. 

/* Stop the listener */

$ lsnrctl stop

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully

/* Shutdown the database itself */

$ sqlplus / as sysdba

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 

Take a backup of Oracle Home and Database

Once the oracle database is shutdown, take a cold backup of your database and a backup of your ORACLE_HOME.
$cd /u01/apps/oracle/oradata/

/*
 All my data files , control files and log files are in a directory ora10g
 at the location /u01/apps/oracle/oradata/.
 I am going to make a tar archive of ora10g directory. If these files
 are at separate locations then add all those locations into the tar archive.
 And since this is just a test database and is very small in size so tar archive
 works much better then every thing else. But if it would be a production db and 
 is big in size then I would consider other faster ways to take a cold backup of
 my data files.
*/

$ tar czf /home/oracle/ora10g.tar.gz ora10g

$ echo $ORACLE_HOME
/u01/apps/oracle/product/10.2.0/db_1

/*
 This is my ORACLE_HOME so I would make a tar archive of "db_1" directory.
*/

$ cd /u01/apps/oracle/product/10.2.0/
$ tar czf /home/oracle/oraHomeBackup.tar.gz db_1

Manage your data with TimeZone before upgrade


(Only perform this step if you have data or Scheduler jobs with TZ info) From 9i onwards Oracle has 2 datatypes that may have data stored affected by a update of the RDBMS DST (Daylight Saving Time) definitions, those are TIMESTAMP WITH LOCAL TIME ZONE (TSLTZ) and TIMESTAMP WITH TIME ZONE (TSTZ). If you have TZ data stored in your database you need to go through the following steps to ensure the integrity of your data while the database upgrade.
Check which TIMEZONE version file you are currently using.
SQL> select version from v$timezone_file;

   VERSION
----------
         2
If this gives 4 then you may simply proceed with the upgrade even if you have TZ data.
If this gives higher then 4, look at the meta link note: Note 553812.1
If this gives lower then 4, perform the following steps:
Download utltzpv4.sql and run it.
SQL> @utltzpv4.sql    
DROP TABLE sys.sys_tzuv2_temptab CASCADE CONSTRAINTS
               *
ERROR at line 1:
ORA-00942: table or view does not exist



Table created.

DROP TABLE sys.sys_tzuv2_affected_regions CASCADE CONSTRAINTS
               *
ERROR at line 1:
ORA-00942: table or view does not exist



Table created.

Your current timezone version is 2!
.
Do a select * from sys.sys_tzuv2_temptab; to see if any TIMEZONE
data is affected by version 4 transition rules.
.
Any table with YES in the nested_tab column (last column) needs
a manual check as these are nested tables.

PL/SQL procedure successfully completed.


Commit complete.

SQL> 

/* Once the script finishes successfully execute the following query */

column table_owner format a4
column column_name format a18
select * from sys_tzuv2_temptab;

TABL TABLE_NAME                     COLUMN_NAME          ROWCOUNT NES
---- ------------------------------ ------------------ ---------- ---
SYS  SCHEDULER$_JOB                 LAST_ENABLED_TIME           3
SYS  SCHEDULER$_JOB                 LAST_END_DATE               1
SYS  SCHEDULER$_JOB                 LAST_START_DATE             1
SYS  SCHEDULER$_JOB                 NEXT_RUN_DATE               1
SYS  SCHEDULER$_JOB                 START_DATE                  1
SYS  SCHEDULER$_JOB_RUN_DETAILS     REQ_START_DATE              1
SYS  SCHEDULER$_JOB_RUN_DETAILS     START_DATE                  1
SYS  SCHEDULER$_WINDOW              LAST_START_DATE             2
SYS  SCHEDULER$_WINDOW              NEXT_START_DATE             2

9 rows selected.
If it returns no rows, there is nothing that needs to be done. Just proceed with the upgrade.
If it retunrs the detail of columns that contain TZ data which may be affected by the upgrade, see metalink note: Note 553812.1
The Note 553812.1 states that if you see SYS owned SCHEDULER objects then it is safe to ignore them and proceed with the upgrade. But if you see user data or user created jobs here then you need to take a backup of data before upgrade and restore it back after the upgrade. Remove any user created jobs and re-create them after the upgrade.

Download Oracle Patchset 10.2.0.4 (6810189)

Now is the time to prepare the oracle 10.2.0.4 patchset installer.
You can download the patchset from

For Linux x86 (32-bit):

10.2.0.4 for Linux x86

For Linux x86-64 (64-bit):

10.2.0.4 for Linux x86-64
Once downloaded login as root in another console and execute following:
# xhost +SI:localuser:oracle

Install the patchset 10.2.0.4

Now come back to the oracle user console and move to the directory where you downloaded the patch and unzip the file.
$ cd /home/oracle
$ unzip p6810189_10204_Linux-x86.zip
$ cd Disk1/
$ ./runInstaller
The first screen is welcome screen.
Oracle patchset 10.2.0.4 Installer Welcome page Provide the Oracle home details here (The oracle 10.2.0.1 home).
Oracle patchset 10.2.0.4 Installer Orale Home Details The installer will perform prerequisite checks on this screen. Make sure you see the message "The overall result of this check is passed" in the output.
Oracle patchset 10.2.0.4 Installer Prerequisites Checks Oracle configuration Manager allows you to associate your configuration with your metalink support account. You may skip this.
Oracle patchset 10.2.0.4 Installer Configuration Manager Installation Summary.
Oracle patchset 10.2.0.4 Installer Summary Installation progress.
Oracle patchset 10.2.0.4 Installer Progress Once progress shows 100%, you will be asked to perform some root specific actions.
Oracle patchset 10.2.0.4 Installer Root specific Login as root
# which dbhome
/usr/local/bin/dbhome
/* 
   this shows the location of dbhome, oraenv and coraenv files
   rename them for 10.2.0.1 as the root.sh create new ones for 
   10.2.0.4
*/
# cd /usr/local/bin/
# mv dbhome dbhome_10201
# mv oraenv oraenv_10201
# mv coraenv coraenv_10201

/* Now execute the script suggested by the installer. */

# /u01/apps/oracle/product/10.2.0/db_1/root.sh
Running Oracle10 root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/apps/oracle/product/10.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
When root.sh finishes successfully come back to installer and press ok. Then you should see the End of Installation page as below.
Welcome Oracle patchset 10.2.0.4 Installer End of Installation Press exit and your ORACLE_HOME is patched with 10.2.0.4 patchset. All your db's working under this ORACLE_HOME will become unusable unless you upgrade your database to 10.2.04 as well.
$ sqlplus / as sysdba

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  608174080 bytes
Fixed Size                  1268896 bytes
Variable Size             171967328 bytes
Database Buffers          427819008 bytes
Redo Buffers                7118848 bytes
Database mounted.
ORA-01092: ORACLE instance terminated. Disconnection forced

SQL> exit
As you can see the database is unable to open and throwing the error ORA-01092. Lets look at the alert log file to know what actually happened.
$ tail -f /u01/apps/oracle/admin/ora10g/bdump/alert_ora10g.log 
SMON: enabling cache recovery
Fri Jul  2 15:30:15 2010
Errors in file /u01/apps/oracle/admin/ora10g/udump/ora10g_ora_12856.trc:
ORA-00704: bootstrap process failure
ORA-39700: database must be opened with UPGRADE option
Fri Jul  2 15:30:15 2010
Error 704 happened during db open, shutting down database
USER: terminating instance due to error 704
Instance terminated by USER, pid = 12856
ORA-1092 signalled during: ALTER DATABASE OPEN...
$
The alert log states that the database has to be upgraded first using UPGRADE option to be able to OPEN normally.

Upgrade the database from 10.2.0.1 to 10.2.0.4

Now startup the database with upgrade option and run the pre-upgrade information tool to see if the database is okay for the upgrade and if there is some thing to be changed before starting the upgrade.
$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus / as sysdba

SQL> startup upgrade

SQL> spool pre_upgrade.log

SQL> @utlu102i.sql
Oracle Database 10.2 Upgrade Information Utility    07-02-2010 17:39:25
.
**********************************************************************
Database:
**********************************************************************
--> name:       ORA10G
--> version:    10.2.0.1.0
--> compatible: 10.2.0.1.0
--> blocksize:  8192
.
**********************************************************************
Tablespaces: [make adjustments in the current environment]
**********************************************************************
--> SYSTEM tablespace is adequate for the upgrade.
.... minimum required size: 488 MB
.... AUTOEXTEND additional space required: 8 MB
--> UNDOTBS1 tablespace is adequate for the upgrade.
.... minimum required size: 400 MB
.... AUTOEXTEND additional space required: 370 MB
--> SYSAUX tablespace is adequate for the upgrade.
.... minimum required size: 245 MB
.... AUTOEXTEND additional space required: 15 MB
--> TEMP tablespace is adequate for the upgrade.
.... minimum required size: 58 MB
.... AUTOEXTEND additional space required: 38 MB
--> EXAMPLE tablespace is adequate for the upgrade.
.... minimum required size: 69 MB
.
**********************************************************************
Update Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
-- No update parameter changes are required.
.
**********************************************************************
Renamed Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
-- No renamed parameters found. No changes are required.
.
**********************************************************************
Obsolete/Deprecated Parameters: [Update Oracle Database 10.2 init.ora or spfile]
**********************************************************************
-- No obsolete parameters found. No changes are required
.
**********************************************************************
Components: [The following database components will be upgraded or installed]
**********************************************************************
--> Oracle Catalog Views         [upgrade]  VALID
--> Oracle Packages and Types    [upgrade]  VALID
--> JServer JAVA Virtual Machine [upgrade]  VALID
--> Oracle XDK for Java          [upgrade]  VALID
--> Oracle Java Packages         [upgrade]  VALID
--> Oracle Text                  [upgrade]  VALID
--> Oracle XML Database          [upgrade]  VALID
--> Oracle Workspace Manager     [upgrade]  VALID
--> Oracle Data Mining           [upgrade]  VALID
--> OLAP Analytic Workspace      [upgrade]  VALID
--> OLAP Catalog                 [upgrade]  VALID
--> Oracle OLAP API              [upgrade]  VALID
--> Oracle interMedia            [upgrade]  VALID
--> Spatial                      [upgrade]  VALID
--> Expression Filter            [upgrade]  VALID
--> EM Repository                [upgrade]  VALID
--> Rule Manager                 [upgrade]  VALID
.

PL/SQL procedure successfully completed.

SQL> spool off
The output from utlu102i.sql shows that every thing is fine, no changes are required and the database is ready for upgrade.
Lets start the upgrade process.
SQL> spool upgrade.log
SQL> @catupgrd.sql
.
.
.
[output trimmed]
.
.
.
Oracle Database 10.2 Upgrade Status Utility           07-02-2010 18:13:40
.
Component                                Status         Version  HH:MM:SS
Oracle Database Server                    VALID      10.2.0.4.0  00:09:32
JServer JAVA Virtual Machine              VALID      10.2.0.4.0  00:03:34
Oracle XDK                                VALID      10.2.0.4.0  00:00:29
Oracle Database Java Packages             VALID      10.2.0.4.0  00:00:39
Oracle Text                               VALID      10.2.0.4.0  00:00:20
Oracle XML Database                       VALID      10.2.0.4.0  00:01:29
Oracle Workspace Manager                  VALID      10.2.0.4.3  00:00:39
Oracle Data Mining                        VALID      10.2.0.4.0  00:00:18
OLAP Analytic Workspace                   VALID      10.2.0.4.0  00:00:19
OLAP Catalog                              VALID      10.2.0.4.0  00:00:50
Oracle OLAP API                           VALID      10.2.0.4.0  00:00:45
Oracle interMedia                         VALID      10.2.0.4.0  00:03:48
Spatial                                   VALID      10.2.0.4.0  00:01:29
Oracle Expression Filter                  VALID      10.2.0.4.0  00:00:09
Oracle Enterprise Manager                 VALID      10.2.0.4.0  00:01:16
Oracle Rule Manager                       VALID      10.2.0.4.0  00:00:07
.
Total Upgrade Time: 00:25:52
DOC>#######################################################################
DOC>#######################################################################
DOC>
DOC>   The above PL/SQL lists the SERVER components in the upgraded
DOC>   database, along with their current version and status.
DOC>
DOC>   Please review the status and version columns and look for
DOC>   any errors in the spool log file.  If there are errors in the spool
DOC>   file, or any components are not VALID or not the current version,
DOC>   consult the Oracle Database Upgrade Guide for troubleshooting
DOC>   recommendations.
DOC>
DOC>   Next shutdown immediate, restart for normal operation, and then
DOC>   run utlrp.sql to recompile any invalid application objects.
DOC>
DOC>#######################################################################
DOC>#######################################################################
DOC>#
SQL> spool off
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
When the upgrade script catupgrd.sql finishes shutdown the database and open the spool of the upgrade process and try to find out if any thing failed. If you see something failed try to fix it and re-run the upgrade process.
The upgrade process may leave many objects invalid in the database. Perform a normal startup and run the utlrp.sql script to recompile any invalid objects.
$ sqlplus / as sysdba

Connected to an idle instance.

SQL> startup

SQL> spool recompile.log

SQL> @utlrp.sql

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN  2010-07-02 18:23:16

DOC>   The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC>   objects in the database. Recompilation time is proportional to the
DOC>   number of invalid objects in the database, so this command may take
DOC>   a long time to execute on a database with a large number of invalid
DOC>   objects.
DOC>
DOC>   Use the following queries to track recompilation progress:
DOC>
DOC>   1. Query returning the number of invalid objects remaining. This
DOC>      number should decrease with time.
DOC>         SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC>   2. Query returning the number of objects compiled so far. This number
DOC>      should increase with time.
DOC>         SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC>   This script automatically chooses serial or parallel recompilation
DOC>   based on the number of CPUs available (parameter cpu_count) multiplied
DOC>   by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC>   On RAC, this number is added across all RAC nodes.
DOC>
DOC>   UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC>   recompilation. Jobs are created without instance affinity so that they
DOC>   can migrate across RAC nodes. Use the following queries to verify
DOC>   whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC>   1. Query showing jobs created by UTL_RECOMP
DOC>         SELECT job_name FROM dba_scheduler_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC>   2. Query showing UTL_RECOMP jobs that are running
DOC>         SELECT job_name FROM dba_scheduler_running_jobs
DOC>            WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#

PL/SQL procedure successfully completed.


TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END  2010-07-02 18:23:50


PL/SQL procedure successfully completed.

DOC> The following query reports the number of objects that have compiled
DOC> with errors (objects that compile with errors have status set to 3 in
DOC> obj$). If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#

OBJECTS WITH ERRORS
-------------------
                  0

DOC> The following query reports the number of errors caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC>#

ERRORS DURING RECOMPILATION
---------------------------
                          0


PL/SQL procedure successfully completed.

SQL> spool off

/*
  When the script utlrp.sql completes go ahead and verify if all the components are 
  upgraded to 10.2.0.4
*/
set lines 10000
set pages 1000
column comp_name format a40
column version format a12
column status format a6
select comp_name, version, status from sys.dba_registry;

COMP_NAME                                VERSION      STATUS
---------------------------------------- ------------ ------
Oracle Database Catalog Views            10.2.0.4.0   VALID
Oracle Database Packages and Types       10.2.0.4.0   VALID
Oracle Workspace Manager                 10.2.0.4.3   VALID
JServer JAVA Virtual Machine             10.2.0.4.0   VALID
Oracle XDK                               10.2.0.4.0   VALID
Oracle Database Java Packages            10.2.0.4.0   VALID
Oracle Expression Filter                 10.2.0.4.0   VALID
Oracle Data Mining                       10.2.0.4.0   VALID
Oracle Text                              10.2.0.4.0   VALID
Oracle XML Database                      10.2.0.4.0   VALID
Oracle Rule Manager                      10.2.0.4.0   VALID
Oracle interMedia                        10.2.0.4.0   VALID
OLAP Analytic Workspace                  10.2.0.4.0   VALID
Oracle OLAP API                          10.2.0.4.0   VALID
OLAP Catalog                             10.2.0.4.0   VALID
Spatial                                  10.2.0.4.0   VALID
Oracle Enterprise Manager                10.2.0.4.0   VALID

17 rows selected.
The above query shows that the database components are at 10.2.0.4 version now.

Restore the database back to 10.2.0.1 if any thing failed

Let's suppse the upgrade process fails, then you can always go back to 10.2.0.1 level be restoring the backup we took at the beginning of the process and start over the upgrade.
Just shutdown the database and restore the backups as follows:
$ echo $ORACLE_HOME
/u01/apps/oracle/product/10.2.0/db_1

$ cd /u01/apps/oracle/product/10.2.0/
$ rm -fr db_1
$ tar xzf /home/oracle/oraHomeBackup.tar.gz *

/* This will restore the old ORACLE_HOME */

$ cd /u01/apps/oracle/oradata/
$ rm -fr ora10g
$ tar xzf /home/oracle/ora10g.tar.gz *

/* This will restore a consistent copy of datafiles, controlfiles and redo log files */
Now start the database and see which version is it?
$ sqlplus / as sysdba

Connected to an idle instance.

SQL> startup

set lines 10000
set pages 1000
column comp_name format a40
column version format a12
column status format a6
select comp_name, version, status from sys.dba_registry;

COMP_NAME                                VERSION      STATUS
---------------------------------------- ------------ ------
Oracle Database Catalog Views            10.2.0.1.0   VALID
Oracle Database Packages and Types       10.2.0.1.0   VALID
Oracle Workspace Manager                 10.2.0.1.0   VALID
JServer JAVA Virtual Machine             10.2.0.1.0   VALID
Oracle XDK                               10.2.0.1.0   VALID
Oracle Database Java Packages            10.2.0.1.0   VALID
Oracle Expression Filter                 10.2.0.1.0   VALID
Oracle Data Mining                       10.2.0.1.0   VALID
Oracle Text                              10.2.0.1.0   VALID
Oracle XML Database                      10.2.0.1.0   VALID
Oracle Rules Manager                     10.2.0.1.0   VALID
Oracle interMedia                        10.2.0.1.0   VALID
OLAP Analytic Workspace                  10.2.0.1.0   VALID
Oracle OLAP API                          10.2.0.1.0   VALID
OLAP Catalog                             10.2.0.1.0   VALID
Spatial                                  10.2.0.1.0   VALID
Oracle Enterprise Manager                10.2.0.1.0   VALID

17 rows selected.
We are back again from where we started.



Using DBUA for upgrade to 11.2.0.2

Using DBUA for upgrade to 11.2.0.2

This is a brief post, originating from an earlier request, related to using DBUA for database upgrade to 11.2.0.2. Screenshots in the posts are on Windows platform but the concept is similar on Linux/Unix.
Start DBUA. Press Next.

Select the database to upgrade. Make sure that the database version supports direct upgrade. Here I have 11.1.0.7, 10.2.0.4 and 11.2.0.1 and all of them maintain direct upgrade. For details see (Oracle 11gR1 Upgrade Companion [ID 601807.1], 10g Upgrade Companion [ID 466181.1] and Oracle 11gR2 Upgrade Companion [ID 785351.1]). Here 11gR1 database is selected. If a direct upgrade is possible dbua is doing all the work for us and the screens are similar regardless of the database version as far as a direct upgrade is supported.


Accept the Warning. It is related to the Ultra Search de-support in 11gR2and the lack of ability to downgrade the OEM Database Control after the upgrade.

Select the degree of parallelism to be used for recompilation of invalid objects (equivalent of running the utlrp.sql), upgrade of the time zone and the option to backup the database.

Select the option to move the data files as part of the upgrade. Select a file system as a target location and press Next.

Review the Upgrade summary and press Finish for the upgrade to start.

The ordered list of actions and their progress appears on the screen. Wait until completion.

When 100% of the work is done press OK to see the results.

Here is a summary of the performed upgrade. Press Close to exit.



Monday, 16 May 2011

exp filesize

exp SCOTT/TIGER FILE=D:F1.dmp,E:F2.dmp FILESIZE=10m LOG=scott.log

Lock

SELECT c.owner, c.object_name, c.object_type, b.SID, b.serial#, b.status,
       b.osuser, b.machine
  FROM v$locked_object a, v$session b, dba_objects c
 WHERE b.SID = a.session_id AND a.object_id = c.object_id;

alter system kill session '382,37491';

SQL> select s.sid,s.serial#,s.status,p.spid from v$session s,v$process p where s .username='QAV43' and p.addr=s.paddr;
 SID    SERIAL# STATUS   SPID
---------- ---------- -------- ------------
129      36971 INACTIVE 23892
125       1632 INACTIVE 23900

SQL>alter system kill session '125,1632';

TAF service

Add a new TAF service with dbca

I needed to set up a new service for my three nodes Oracle RAC production environment.
I decided to use dbca because it's easier compared with srvctl command line.
Indeed when you use DBCA to create a service you do not need to add the corresponding TNS entry in your tnsnames.ora on the cluster nodes: DBCA does it all for you in the background.
Of course you can use SRVCTL to create a service, but you also need to manually add the TNS entry: moreover when you use SRVCTL, after you've created the new service you need to start it with a separate command, while DBCA starts it when you click FINISH button.
So let's start logging as oracle user from one of your nodes, and type
dbca



It first shows the Welcome window where you need to select your type of database: Oracle Real Application Cluster database or Oracle single instance database.



Next you need to choose the operation to be performed. Choose Services Management and click NEXT button.



At the step 2 select your database. In my case the screen shows my only BILLING database



The step 3 shows the current services available for the database chosen. In this screen you can add, remove or modify services. Today we want to add a new service so click the ADD button.



After clicking the ADD button you can choose a name for next service: in my case I called it SIM_TAF. Press OK button after you enter your service name.



Now configure your option for the new service. I choose it should have only a preferred instance where to run (BILLING3) and two available instances to switch over in case of problems (BILLING1 and BILLING2). Choose also your TAF (Transparent Application Failover) policy:
transparent application failover is a client-side feature that allows for clients to reconnect to surviving databases in the event of a failure of a database instance. Notifications are used by the server to trigger TAF callbacks on the client-side. Your options could be: Basic, in which the application connects to a backup node only after the primary connection fails. This approach has low overhead, but the end user experiences a delay while the new connection is created, or Pre-Connect, where the application simultaneously connects to both a primary and a backup node. This offers faster failover, because a pre-spawned connection is ready to use. But the extra connection adds everyday overhead by duplicating connections. For my environment Basic TAF policy was good. Click FINISH.



A summary screen will appear. Click OK



The configuration of the new service will start



Click NO if you don't want to perform other operation.



That's all.