TIP #38 : Tracing session with 10046 event

Using event 10046 is a common way to gather extended information about sessions which mostly is useful got performance analysis.
Here are different tips on how to enable it and how to read its output.

Enabling trace for session.
  1. alter session set timed_statistics = true;
  2. alter session set statistics_level=all;
  3. alter session set max_dump_file_size = unlimited;
  4. alter session set events '10046 trace name context forever,level 12' ; 12 will trace wait_events and bind variables;

Disabling trace for a session.

  1. alter session set events '10046 trace name context off';

Tracing existing process

  • Find SID of that session
  • Find its OS pid from the following (This does not work for Windows)
  • select p.PID,p.SPID,s.SID from v$process p,v$session s where s.paddr = p.addr and s.sid = &SESSION_ID;
  • oradebug setospid spid??? (spid from above query)
  • oradebug unlimit
  • oradebug event 10046 trace name context forever,level 12;

OR

  • Find SID of that session
  • Find its Orable pid from the following (This does work for Windows)
    select p.PID,p.SPID,s.SID from v$process p,v$session s where s.paddr = p.addr and s.sid = &SESSION_ID;
  • oradebug setorapid pid??? (pid from above query)
  • oradebug unlimit
  • oradebug event 10046 trace name context forever,level 12;

Disable Tracing of existing session

  • oradebug event 10046 trace name context off

Enabling Trace on user login with trigger

CREATE OR REPLACE TRIGGER SYS.set_trace AFTER LOGON ON DATABASE WHEN (USER like '&USERNAME') DECLARE lcommand varchar(200);

BEGIN

EXECUTE IMMEDIATE 'alter session set statistics_level=ALL';

EXECUTE IMMEDIATE 'alter session set max_dump_file_size=UNLIMITED';

EXECUTE IMMEDIATE 'alter session set events ''10046 trace name context forever, level 12''';

END set_trace;

Enabling trace on whole instance.

alter system set events '10046 trace name context forever,level 12';

Disabling trace on whole instance

alter system set events '10046 trace name context off';

How to interpret trace file

Trace file is created in user_dump_dest.There is TKPROF traditional way to make trace file more readable but what I `d like are the following 2 tools which create HTML report.

  • ORASRP (oracledba.ru/orasrp) : OpenSource , available in Windows and Linux
  • TRCANLZR (Metalink note:224270.1) : Creates stored-procedure and bunch of tables in Oracle database, Available on any platform which oracle is available.

TIP #37: Update massive number of records.

In order to update large number of records in table, it is better off to follow below steps.
  • create table new_table as select from old_table?
  • index new_table
  • grant on new table
  • constraints on new table
  • drop old_table
  • rename new_table to old_table.

During table creation, nologging and parallel query can be used. This way also generate less redo and no undo.

TIP #36: Why Oracle from Tom `s point of view.

From ASK TOM site , I found a cool document which TOM answered why Oracle and why not other DBs. Reading of that is full of fun.

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:1886476148373

TIP #35 : 10g editions.

Oracle release four edition for 10g.
  1. Express Edition
  2. Standard Edition One
  3. Standard Edition
  4. Enterprise Edition

Express Edition :

  • Entry level database based on Oracle
  • Free to develop, deploy and distribute
  • 1 CPU limit

Standard Edition One :

  • Full featured database which suits for small-to-medium business
  • 2 CPU limit.
  • Reasonable price. 149$/user with 5 users minimum.

Standard Edition

  • Full featured database for small-to-medium business.
  • Mostly address performance, availability, scalability and security
  • 4 CPU limit.

Enterprise Edition

  • Full featured database for enterprise class business
  • No limitation in CPU.
  • Suitable for transaction processing, BI and content management applications.

For details, refer to http://www.oracle.com/database/product_editions.html

TIP #34 : Oracle price.

For having better understanding of Oracle prices, Please refoer to the following URL.

http://www.oracle.com/corporate/pricing/index.html

TIP #33 : Find out patches which were applied on Oracle/Database

Find out latest patch which was applied to Oracle home : opatch lsinventory (Valid for >=9i)
Find out latest patch which was applied to Database : select * from registry$history;

TIP #32 : Oracle trace events

Full list of different Oracle trace evnts and their brief functionality can be found in :

https://netfiles.uiuc.edu/jstrode/www/oraparm/events.html

TIP #31: Jobs in dba_jobs are not running as per schedule

Today, I faced with strange situation for a client. I submitted a job in dba_jobs with a minute interval. This job was running simple stored procedure.
Job was not run every minute while manual run (with dbms_job.run) was successful.
Job_queue_process was 10 and _job_queue_inteval was 5 which means scheduler checks job for execution every 5 seconds.
Eventually found that background process cjq0 was the culprit.This background process is responsible for running scheduled job.It does initiate J00 processes for executing scheduled jobs.
This background process was hung, as the result it does not initiate any J00 process which means job was not run every minutes.

Resolution :

  1. Kill cjq0 process from OS
  2. alter system set job_queue_process=0;
  3. alter system set job_queue_process=10;
  4. Should fork new cjq0 process and all J00 process for running jobs.

TIP #30 : Find out Application server tier from metarepository database.

To find out InfraAS home and MidAS home relevant to metarepository database, please run the followings :

select * from dcm.tm_instances;

Above queries show hostname,hostaddress of infraAS and midAS.

TIP #29 : RMAN and Resetlogs in 10g.

After each incomplete recovery, database should be opened with resetlogs.
In 9i and below, if database is need to be restored to time prior to resetlogs, different incarnation should be restored.In addition, since new log thread starts with number 1 after resetlogs, all previous backups become obsolete.
In 10g, this is not an issue anymore. RMAN can use any backup before or after resetlogs to recover Oracle database.No need to use different incarnation.

TIP #28 : RMAN 10g and incremental backup.

Why incremental backup ?

The most important reason for doing incremental backups is associated with data warehouse environments, where many operations are done in NOLOGGING mode and data changes do not go to the archived log files.
Considering the massive size of data warehouses today, and the fact that most of the data in them does not change, full backups are neither desirable nor practical. Therefore , doing incremental backups in RMAN is an ideal alternative.

WhyDBAs dis not like incremental backup in 9i ?

Oracle does full scan for finding changes in 9i which generates some performance problem.This is why most DBAs did not like incremental backup in 9i.

What is new with 10g incremental backup ?

Block changes can be tracked in 10g which means that Oracle does not need to do full scan anymore to find out changes.
To enable track changing run the following command.

alter database enable block change tracking using file '/rman_bkups/change.log';

To disable block track change.

alter database disable block change tracking;

TIP #27 : Required RMAN backups for restore.

In 10g, before doing recovery, it is possible to find out backups required to perform a restore operation.This feature is called recovery preview and can be done by adding preview at the end of restore command.

restore database preview;

It can also be run for specific restore operation.

restore tablespace users preview;

TIP #26 : UNDO tablespace recovery.

Here is handy steps for any UNDO tablespace issue.
Some example are :
  • undo tablespace was dropped
  • undo was not recreated
  • undo was recreated without specifying 'undo' keyword.

To resolve the issue, Follow the following steps :

  1. set undo_management to MANUAL
  2. startup pfile
  3. drop undo tablespace (If it was created wrongly without undo keyword)
  4. create undo tablespace undotbs datafile '??????' size 1M reuse;
  5. shutdown database.
  6. set undo_management to AUTO-
  7. startup

TIP #25: Estimate backup size (1)

Before taking a backup, it would be idea to estimate backup size.With Estimation of backup size, we can make sure that there is enough disk space for backup.
Regarding to my investigation, there is no official way to find backup size before taking backup.
However, Oracle comments is : "RMAN does not take backup from NEVER USED blocks" .
Never used blocks are blocks which have not ever been touched.It is different from empty blocks. From the following sample test which I ran, I found that empty blocks were definitely backed up.

Test
=====

== Scenario1 : Create new tablespace and backup (TS size:200M)

SQL> create tablespace rmantst datafile 'C:\ORACLE\ORADATA\ORA10GPR\rmantst.dbf' size 200M;
Tablespace created.
RMAN> connect target /
connected to target database: ORA10GPR (DBID=1394790175)
RMAN> run

2> {
3> backup tablespace rmantst format 'c:\backup_after_ts_creation_%s.bak';
4> }

Starting backup at 28-FEB-07
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=138 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00008 name=C:\ORACLE\ORADATA\ORA10GPR\RMANTST.DBF
channel ORA_DISK_1: starting piece 1 at 28-FEB-07
channel ORA_DISK_1: finished piece 1 at 28-FEB-07
piece handle=C:\BACKUP_AFTER_TS_CREATION_29.BAK tag=TAG20070228T225029 comment=N
ONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 28-FEB-07
Starting Control File and SPFILE Autobackup at 28-FEB-07
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORA10GPR\AUTOBACKUP\2007_02_28\O1_MF_
S_615768645_2YDMDPG5_.BKP comment=NONE
Finished Control File and SPFILE Autobackup at 28-FEB-07
RMAN>

BACKUP_AFTER_TS_CREATION_29.BAK ==> 96KB.

== Scenario2 : Fill up tablespace with data (Fill 163MB of 200MB tablespace)

SQL> create table rmantest1 tablespace rmantst as select * from dba_objects;
Table created.
SQL> create table rmantest2 tablespace rmantst as select * from SOURCE$;
Table created.
SQL> create table rmantest3 tablespace rmantst as select * from SOURCE$;
Table created.
SQL> create table rmantest4 tablespace rmantst as select * from SOURCE$ nologging;
Table created.
SQL> select sum(bytes)/1024/1024 from dba_data_files where tablespace_name='RMANTST';

SUM(BYTES)/1024/1024
--------------------
200


SQL> select sum(bytes)/1024/1024 from dba_free_space where tablespace_name='RMANTST';
SUM(BYTES)/1024/1024
--------------------
37.9375


SQL> select sum(bytes)/1024/1024 from dba_segments where tablespace_name='RMANTST';
SUM(BYTES)/1024/1024
--------------------
162


BACKUP_AFTER_TABLES_CREATION_IN_TS_31.BAK ==> 163 MB.

== Scenario3 : Delete Objects in tablespace (Remove most objects ... Only 6MB was allocated for 200MB tablespace)

SQL> truncate table rmantest2;
Table truncated.
SQL> truncate table rmantest3;
Table truncated.
SQL> truncate table rmantest4;
Table truncated.

SQL> select sum(bytes)/1024/1024 from dba_data_files where tablespace_name='RMANTST';
SUM(BYTES)/1024/1024
--------------------
200
SQL> select sum(bytes)/1024/1024 from dba_free_space where tablespace_name='RMANTST';
SUM(BYTES)/1024/1024
--------------------
193.75
SQL> select sum(bytes)/1024/1024 from dba_segments where tablespace_name='RMANTST';
SUM(BYTES)/1024/1024
--------------------
6.1875 Only 6.1MB was allocated in RMANTST

RMAN> run
2> {
3> backup tablespace rmantst format 'c:\backup_after_tables_truncate_in_ts_%s.ba
k';
4> }
Starting backup at 28-FEB-07
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00008 name=C:\ORACLE\ORADATA\ORA10GPR\RMANTST.DBF
channel ORA_DISK_1: starting piece 1 at 28-FEB-07
channel ORA_DISK_1: finished piece 1 at 28-FEB-07
piece handle=C:\BACKUP_AFTER_TABLES_TRUNCATE_IN_TS_33.BAK tag=TAG20070228T231456
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 28-FEB-07
Starting Control File and SPFILE Autobackup at 28-FEB-07
piece handle=C:\ORACLE\FLASH_RECOVERY_AREA\ORA10GPR\AUTOBACKUP\2007_02_28\O1_MF_
S_615770131_2YDNV53F_.BKP comment=NONE
Finished Control File and SPFILE Autobackup at 28-FEB-07

BACKUP_AFTER_TABLES_TRUNCATE_IN_TS_33.BAK ==> 163 M <== This proves that only NEVER used blocks are not being backed up. EMPTY blocks are backed up if they have already been touched. Therefore, it is not true to say dba_segments can always give backup size .

FYI : Scenarios were run in 10.2.0.1. I will test these in 10.2.0.2