Saturday, 11 October 2008

NID - Bug

There is a funny bug in NID utility, NID can be used to change the name of the database. if your control files does not have .ctl extension or Data files does not have .dbf extension or redo log files has .log extension it will fail stating files can not be recognized.

Once you will rename the files then you can use nid.

But why to go this way then re-create control file only.

:)

Enjoy reading.

Tracing made easy !!

It has always been a challenge to trace a Oracle session or tuning a query..

1) In order to tune SQL there are few commmands which are important.

set autotrace on

set autotrace traceonly

set autotrace traceonly explain

set autotrace traceonly statistics

set autotrace off

2) Tracing a session

Tracing your own session
alter session set tracefile_identifier='EOD_TEST';
alter session set statistics_level = all;
alter session set max_dump_file_size = unlimited;
alter session set events '10046 trace name context forever, level 12';

Tracing other session

-- select OSPID from v$process for specific session

oradebug setospid X
oradebug unlimit
oradebug Event 10046 trace name context forever, level 12

Another method

connect sys as sysdba

exec dbms_system.set_sql_trace_in_session(session's id,serial number, true)


There are few other trace level which i use often to tune the system.

Active Session History alter session set events 'immediate trace name ashdump level 10';
Control File Dump alter session set events 'immediate trace name CONTROLF level 10';

Error Stack (Exception) Trace alter session set events ' trace name errorstack level 10';
alter session set events '60 trace name errorstack level 10';

File Header Dump alter session set events 'immediate trace name FILE_HDRS level 10';
Library Cache Dump alter session set events 'immediate trace name LIBRARY_CACHE level 10';
Process State Dump alter session set events 'immediate trace name PROCESSSTATE LEVEL 10';
Redo Log Headers Dump alter session set events 'immediate trace name REDOHDR LEVEL 10';
System State Dump alter session set events 'immediate trace name SYSTEMSTATE LEVEL 10';

Monday, 14 April 2008

How to change database name and DBID for existing database

Subject : How to change database name and DBID for existing database.Version ; Oracle 10.2.0.3

SQL> select name from v$database;

NAME
---------
TESTDB1

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
testdb1

So the aim is to change DATABASE name to TESTDB So the magical statement is

nid target=sys/change_on_install dbname=testdb logfile=convert_db

DBNEWID: Release 10.2.0.3.0 - Production on Mon Apr 14 13:14:25 2008

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

Connected to database TESTDB1 (DBID=403517258)

Connected to server version 10.2.0

Control Files in database:
/u99/oradata/testdb1/data/testdb1ctrl001.ctl
/u99/oradata/testdb1/data/testdb1ctrl002.ctl
/u99/oradata/testdb1/data/testdb1ctrl003.ctl

Changing database ID from 403517258 to 2435353265
Changing database name from TESTDB1 to TESTDB
Control File /u99/oradata/testdb1/data/testdb1ctrl001.ctl - modified
Control File /u99/oradata/testdb1/data/testdb1ctrl002.ctl - modified
Control File /u99/oradata/testdb1/data/testdb1ctrl003.ctl - modified
Datafile /u99/oradata/testdb1/data/system01.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/undotbs01.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/sysaux01.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/tab01.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/tab02.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/tab01_02.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/undotbs02.dbf - dbid changed, wrote new name
Datafile /u99/oradata/testdb1/data/temp01.dbf - dbid changed, wrote new name
Control File /u99/oradata/testdb1/data/testdb1ctrl001.ctl - dbid changed, wrote new name
Control File /u99/oradata/testdb1/data/testdb1ctrl002.ctl - dbid changed, wrote new name
Control File /u99/oradata/testdb1/data/testdb1ctrl003.ctl - dbid changed, wrote new name
Instance shut down

Database name changed to TESTDB.
Modify parameter file and generate a new password file before restarting.
Database ID for database TESTDB changed to 2435353265.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.


It will shutdown the running instance.if you will try to start without changing the database name in initfile.

ORA-01103: database name 'TESTDB' in control file is not 'TESTDB1'

So , change back the cluster_database to true and change the database name as well.

then

alter database open resetlogs;

How to convert single instance to RAC database !!

Subject : How to convert single instance database to RAC enabled Database ( Multi instance )
Version : Oracle 10.2.0.3


There are three ways to do it.

1) Manual process by setting init parameters
2) By using DBCA
3) By using rconfig utility

1)

Prechecks

** Back Up the Original Single-Instance Database
** Perform the Pre-Installation Steps
** Set Up and validate the Cluster, ensure second nodes connected to the cluster by running olsnodes
** Install Oracle Database 10g Software with Real Application Clusters
** Make sure storage area is shared with other node.
** Make sure you have created Oracle Admin folder which are bdump cdump and udump in the correct loacation as per parameter file.
** change the parameter file of instance 1 with following parameters and copy over to second node.

Assue testdb1 is the first instance and testdb2 is the second instance.

testdb1.instance_number=1
testdb1.instance_name='testdb1'
testdb2.instance_number=2
testdb2.instance_name='testdb2'
testdb1.thread=1
testdb2.thread=2
cluster_database=TRUE
cluster_database_instances=2
testdb1.undo_tablespace=undotbs1
testdb2.undo_tablespace=undotbs2


2) It is wizard kind of thing.. So i do not want to focus on it.

3) rconfig is also very interesting one. rconfig can be find $ORACLE_HOME/bin/rconfig , As a oracle user if you would explore $ORACLE_HOME/assistants/rconfig/sampleXMLs and then you will see file called "ConvertToRAC.xml", Where you need to set the parameter which are
required for single to multi instance conversion.

On the seventh line of this file , you need to set values one of below.

YES - Performs a check of prerequisites + conversion
NO - No check of prerequisites straight to conversion
ONLY - only prerequisites check

Save this file to some name say myinputpara.xml

rconfig myinputpara.xml


After converting if you want to change the database name so please refer one of other post.

HTH
Prashant

Thursday, 7 February 2008

How to deal with Block Corruption !!

This is pretty critical and once in a blue moon for Oracle DBAs. But it is really quite interesting if you have some backups available incase you are not able to Fix the Corrupt Block.

Oracle Database version is 9.2.0.4 and standby database is in 9.2.0.8 (Linux).

There is a below tables has got 1 block corrupt.

SQL> select count(1) from TAB1;
select count(1) from TAB1
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 13, block # 477214)
ORA-01110: data file 13: '/usr/oracle/oradata/DATAFILE03.dbf'

It has generated a trace file as well. some glimpses of the trace as well.


Corrupt block relative dba: 0x0340586b (file 13, block 22635)
Bad check value found during backing up datafile
Data in bad block -
type: 6 format: 2 rdba: 0x0340586b
last change scn: 0x0011.6a3987cd seq: 0x1 flg: 0x06
consistency value in tail: 0x87cd0601
check value in block header: 0xd317, computed block checksum: 0x100
spare1: 0x0, spare2: 0x0, spare3: 0x0
***
Reread of blocknum=22635, file=/usr/oracle/oradata/grcbonl/ONLINE03.dbf. found same corrupt data
Sun Feb 3 19:01:05 2008
Errors in file /home/oracle/admin/grcbonl/udump/onlstb_ora_24224.trc:
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory

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

Script to find out which object has got bad block.
13 is the file no. 22635 is the block occured in trace / alert.

select segment_name,segment_type,owner
from sys.dba_extents
where file_id=(13)
and (22635) between block_id and block_id + blocks -1;

SEGMENT_NAME
--------------------------------------------------------------------------------
SEGMENT_TYPE OWNER
------------------ ------------------------------
TAB1
TABLE USER1

**** First you need to create a table which will store object name and what block was corrupt.

Step 1 : exec DBMS_REPAIR.ADMIN_TABLES ('TB_REPAIR',1,1,null);

Step 2:

variable blockno number;

exec sys.DBMS_REPAIR.CHECK_OBJECT('USER1','TAB1',null, 1,'TB_REPAIR', null, null, null, null, :blockno );

print blockno;

Blockno will print how many blocks are corrupt in the object.

Now come to how you can fix the block.

Step 3 :exec DBMS_REPAIR.FIX_CORRUPT_BLOCKS('USER1','TAB1', NULL, 1, 'TB_REPAIR',NULL, :blockno );


print blockno;

It should print the same output as step 2;

If not then Package is not able to fix the corrupt block. Only way you can get data skipping this block or you can recover whole object by using previoud backups.

How to skip the corrupt block.

SQL> SELECT OBJECT_NAME, BLOCK_ID, CORRUPT_TYPE, MARKED_CORRUPT,
CORRUPT_DESCRIPTION, REPAIR_DESCRIPTION
FROM TB_REPAIR;
2 3
OBJECT_NAME BLOCK_ID CORRUPT_TYPE MARKED_COR
------------------------------ ---------- ------------ ----------
CORRUPT_DESCRIPTION
--------------------------------------------------------------------------------
REPAIR_DESCRIPTION
--------------------------------------------------------------------------------
TAB1 477214 6148 TRUE

mark block software corrupt

TAB1 477214 6148 TRUE

mark block software corrupt

OBJECT_NAME BLOCK_ID CORRUPT_TYPE MARKED_COR
------------------------------ ---------- ------------ ----------
CORRUPT_DESCRIPTION
--------------------------------------------------------------------------------
REPAIR_DESCRIPTION
--------------------------------------------------------------------------------



Step 4:

exec DBMS_REPAIR.skip_corrupt_blocks( 'USER1' , 'TAB1' , 1, 1);

Step 5:

exec DBMS_REPAIR.rebuild_freelists( 'USER1' , 'TAB1' , null, 1);

Step 5 will rebuild the freelists for the table

By above method if this does not fix the corrupt block problem. As i mentioned recover the object from the recent backup.

Statspack package Invalid !!

During one of the migration , I saw the statspack is invalid state. It happened because Migration strategy uses export/import. Import was done by using system. When you create Statspack (spcreate) it creates some tables and views in the SYS schema. So during import these were not created due to import was done by system.

Please follow the below script to get STATSPACK in valid state. Let me know incase i have missed something or your problem is any different , i will be happy to address that.

Thanks

===================== Script ==================
alter package statspack compile body;
show errors;
-- See what all objects are missing

GRANT ALTER SESSION TO perfstat;
GRANT CREATE PROCEDURE TO perfstat;
GRANT CREATE PUBLIC SYNONYM TO perfstat;
GRANT CREATE SEQUENCE TO perfstat;
GRANT CREATE SESSION TO perfstat;
GRANT CREATE TABLE TO perfstat;
GRANT DROP PUBLIC SYNONYM TO perfstat;
GRANT EXECUTE ON "SYS"."DBMS_JOB" TO perfstat;
GRANT EXECUTE ON "SYS"."DBMS_SHARED_POOL" TO perfstat;
GRANT SELECT ON "SYS"."STATS$V_$FILESTATXS" TO perfstat;
GRANT SELECT ON "SYS"."STATS$V_$SQLXS" TO perfstat;
GRANT SELECT ON "SYS"."STATS$V_$TEMPSTATXS" TO perfstat;
GRANT SELECT ON "SYS"."STATS$X_$KCBFWAIT" TO perfstat;
GRANT SELECT ON "SYS"."STATS$X_$KSPPI" TO perfstat;
GRANT SELECT ON "SYS"."STATS$X_$KSPPSV" TO perfstat;
GRANT SELECT ON "SYS"."V_$BUFFER_POOL" TO perfstat;
GRANT SELECT ON "SYS"."V_$BUFFER_POOL_STATISTICS" TO perfstat;
GRANT SELECT ON "SYS"."V_$DATABASE" TO perfstat;
GRANT SELECT ON "SYS"."V_$DB_CACHE_ADVICE" TO perfstat;
GRANT SELECT ON "SYS"."V_$DLM_MISC" TO perfstat;
GRANT SELECT ON "SYS"."V_$ENQUEUE_STAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$INSTANCE" TO perfstat;
GRANT SELECT ON "SYS"."V_$INSTANCE_RECOVERY" TO perfstat;
GRANT SELECT ON "SYS"."V_$LATCH" TO perfstat;
GRANT SELECT ON "SYS"."V_$LATCH_CHILDREN" TO perfstat;
GRANT SELECT ON "SYS"."V_$LATCH_MISSES" TO perfstat;
GRANT SELECT ON "SYS"."V_$LATCH_PARENT" TO perfstat;
GRANT SELECT ON "SYS"."V_$LIBRARYCACHE" TO perfstat;
GRANT SELECT ON "SYS"."V_$PARAMETER" TO perfstat;
GRANT SELECT ON "SYS"."V_$PGASTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$PGA_TARGET_ADVICE" TO perfstat;
GRANT SELECT ON "SYS"."V_$RESOURCE_LIMIT" TO perfstat;
GRANT SELECT ON "SYS"."V_$ROLLSTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$ROWCACHE" TO perfstat;
GRANT SELECT ON "SYS"."V_$SEGMENT_STATISTICS" TO perfstat;
GRANT SELECT ON "SYS"."V_$SEGSTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SEGSTAT_NAME" TO perfstat;
GRANT SELECT ON "SYS"."V_$SESSION" TO perfstat;
GRANT SELECT ON "SYS"."V_$SESSION_EVENT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SESSTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SGA" TO perfstat;
GRANT SELECT ON "SYS"."V_$SGASTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SHARED_POOL_ADVICE" TO perfstat;
GRANT SELECT ON "SYS"."V_$SQL" TO perfstat;
GRANT SELECT ON "SYS"."V_$SQLAREA" TO perfstat;
GRANT SELECT ON "SYS"."V_$SQLTEXT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SQL_PLAN" TO perfstat;
GRANT SELECT ON "SYS"."V_$SQL_WORKAREA_HISTOGRAM" TO perfstat;
GRANT SELECT ON "SYS"."V_$SYSSTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SYSTEM_EVENT" TO perfstat;
GRANT SELECT ON "SYS"."V_$SYSTEM_PARAMETER" TO perfstat;
GRANT SELECT ON "SYS"."V_$UNDOSTAT" TO perfstat;
GRANT SELECT ON "SYS"."V_$WAITSTAT" TO perfstat;
GRANT "SELECT_CATALOG_ROLE" TO perfstat;


CREATE OR REPLACE VIEW "SYS"."STATS$V_$SQLXS" ("SQL_TEXT",
"SHARABLE_MEM","SORTS","MODULE","LOADED_VERSIONS","FETCHES",
"EXECUTIONS","LOADS","INVALIDATIONS","PARSE_CALLS",
"DISK_READS","BUFFER_GETS","ROWS_PROCESSED","COMMAND_TYPE",
"ADDRESS","HASH_VALUE","VERSION_COUNT","CPU_TIME",
"ELAPSED_TIME","OUTLINE_SID","OUTLINE_CATEGORY","IS_OBSOLETE",
"CHILD_LATCH") AS
select max(sql_text) sql_text
, sum(sharable_mem) sharable_mem
, sum(sorts) sorts
, min(module) module
, sum(loaded_versions) loaded_versions
, sum(fetches) fetches
, sum(executions) executions
, sum(loads) loads
, sum(invalidations) invalidations
, sum(parse_calls) parse_calls
, sum(disk_reads) disk_reads
, sum(buffer_gets) buffer_gets
, sum(rows_processed) rows_processed
, max(command_type) command_type
, address address
, hash_value hash_value
, count(1) version_count
, sum(cpu_time) cpu_time
, sum(elapsed_time) elapsed_time
, max(outline_sid) outline_sid
, max(outline_category) outline_category
, max(is_obsolete) is_obsolete
, max(child_latch) child_latch
from v$sql
group by hash_value, address
/



grant select on v_$session to perfstat;
grant select on v_$instance to perfstat;
grant select on v_$database to perfstat;
grant select on stats$v$sqlxs to perfstat;


CREATE OR REPLACE VIEW "SYS"."STATS$V_$FILESTATXS" ("TSNAME",
"FILENAME","PHYRDS","PHYWRTS","READTIM","WRITETIM",
"SINGLEBLKRDS","PHYBLKRD","PHYBLKWRT","SINGLEBLKRDTIM",
"WAIT_COUNT","TIME") AS
select ts.name tsname
, df.name filename
, fs.phyrds
, fs.phywrts
, fs.readtim
, fs.writetim
, fs.singleblkrds
, fs.phyblkrd
, fs.phyblkwrt
, fs.singleblkrdtim
, fw.count wait_count
, fw.time time
from x$kcbfwait fw
, v$filestat fs
, v$tablespace ts
, v$datafile df
where ts.ts# = df.ts#
and fs.file# = df.file#
and fw.indx+1 = df.file#
/

grant select on STATS$V_$FILESTATXS to perfstat;


CREATE OR REPLACE VIEW "SYS"."STATS$V_$TEMPSTATXS" ("TSNAME",
"FILENAME","PHYRDS","PHYWRTS","READTIM","WRITETIM",
"SINGLEBLKRDS","PHYBLKRD","PHYBLKWRT","SINGLEBLKRDTIM",
"WAIT_COUNT","TIME") AS
select ts.name tsname
, tf.name filename
, tm.phyrds
, tm.phywrts
, tm.readtim
, tm.writetim
, tm.singleblkrds
, tm.phyblkrd
, tm.phyblkwrt
, tm.singleblkrdtim
, fw.count wait_count
, fw.time time
from x$kcbfwait fw
, v$tempstat tm
, v$tablespace ts
, v$tempfile tf
where ts.ts# = tf.ts#
and tm.file# = tf.file#
and fw.indx+1 = (tf.file# + (select value from v$parameter where name='db_files'))
/


GRANT SELECT ON STATS$V_$TEMPSTATXS TO PERFSTAT;



CREATE OR REPLACE VIEW "SYS"."STATS$X_$KSPPSV" ("ADDR","INDX",
"INST_ID","KSPPSTVL","KSPPSTDF","KSPPSTVF","KSPPSTCMNT") AS
select "ADDR","INDX","INST_ID","KSPPSTVL","KSPPSTDF",
"KSPPSTVF","KSPPSTCMNT"
from X$KSPPSV;

GRANT SELECT ON STATS$X_$KSPPSV TO PERFSTAT;



CREATE OR REPLACE VIEW "SYS"."STATS$X_$KSPPI" ("ADDR","INDX",
"INST_ID","KSPPINM","KSPPITY","KSPPDESC","KSPPIFLG") AS
select "ADDR","INDX","INST_ID","KSPPINM","KSPPITY","KSPPDESC",
"KSPPIFLG"
from X$KSPPI ;

GRANT SELECT ON STATS$X_$KSPPI TO PERFSTAT;


@dbmspool

grant execute on DBMS_SHARED_POOl to perfstat;


alter package statspack compile body;

-- Package body will have no errors.

Monday, 21 January 2008

How to load java in Oracle Database !!

You need to connect as sys and run following statments.

- To Load Java

connect sys/PASSWD as SYSDBA
set echo off
set verify off
@$ORACLE_HOME/javavm/install/initjvm.sql
@$ORACLE_HOME/xdk/admin/initxml.sql
@$ORACLE_HOME/xdk/admin/xmlja.sql
@$ORACLE_HOME/rdbms/admin/catjava.sql

- To load XDB

Please make sure that you have already set the following path before load XDB, else you may hit following errors during loading.

export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LIBPATH=$ORACLE_HOME/lib

Otherwise you get "ORA-00600: internal error code, arguments: [unable to load XDB library], [], [], [], [], [], [], []"

For More info.( please refer note 225897.1Installation of Oracle XDB Fails with ORA-00600 [unable to load XDB library] )

If you want to remove XDB or reload

@${ORACLE_HOME}/rdbms/admin/catnoqm.sql

I would recommend to restart the database for reloading XDB.

Friday, 23 February 2007

Oracle 11g Features

First post is all about features of Oracle 11g

1. New Load balancing utilities (Webserver,RAC,Listner Data Guard).
2. New Data type introduced "simple_integer"
3. Now ADDM is capable of providing advice on Database and Instance.
4. Automatic Memory Tuning of PGA (SGA auto tuning was introduced in 10g) .
5. Case Sensitive passwords.
6. Fully automated SQL tuning. 11g can automatically invoke SQL profiles to replace the problematic statements.
7. Null downtime for Patching and patching can be done according to features.

That's all for today's post, Please let me know if you have any questions / comments.

Welcome to my Blog.

Hello DBAs,

Welcome to blog of Oracle DBAs. This blog is for developer turned DBAs or SQL server DBAs turned Oracle DBAs.

Oracle has the most robust features than any other RDBMS i have ever used. Oracle 11g is on the way it has so many new features. Oracle 11g features.


 

Database Solutions for Oracle/Sql server/DB2 DBAs Copyright © 2009 Premium Blogger Dashboard Designed by SAER