Monday, December 12, 2011

How to Tune query that cannot modify ?



Query cannot be modified as it is hardcoded in an application or is generated by application code.

“Query Tuning issues can often be alleviated by modification of the query in question, either to add

hints or to change the query structure to avoid an issue. However in some cases the query cannot be

modified because it is hardcoded in an application or is generated by application code.

Oracle provides the option of changing the execution plan for running queries, without changing the

code itself. This feature also allows us to insulate our application execution plans against any

structural changes or upgrades. This feature is known as Stored Outlines and the idea is to store

the execution plan in Oracle provided tables, which will later be referred to by the optimizer to
execute the queries, thus providing optimizer plan stability.

Stored outlines are global and apply to all identical statements, regardless of the user firing it.
Under user SYS run $ORACLE_HOME/rdbms/admin/dbmsol.sql”

PARAMETERS TO BE SET
“CREATE_STORED_OUTLINES   Setting this to TRUE or an appropriate category name will automatically enable creating and storing
of outlines for every subsequent query fired. A DEFAULT category is used unless specified.

“”USE_STORED_OUTLINES This parameter enables the use of public stored outlines. Setting USE_STORED_OUTLINES to TRUE causes
the execution plan stored in the DEFAULT category to take effect. Set the parameter to a proper category name to explicitly use a different category.”
“QUERY_REWRITE_ENABLED allows you to enable or disable query rewriting globally for the database”
Example:
“EXAMPLE  1
select * from Joshi;
Execution Plan
———————————————————-
0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=15 Bytes=852)
1    0   TABLE ACCESS (FULL) OF ‘Joshi’ (Cost=1 Card=15 Bytes=852)”
CREATE OUTLINES AND THEN UPDATE THE OL$HINTS VIEW AS FOLLOWING :
“CREATE OR REPLACE OUTLINE ORIGINALSQL ON
select * from Joshi;
CREATE OR REPLACE OUTLINE HINTSQL ON
select /*+ index(Joshi) */  * from Joshi;
UPDATE OUTLN.OL$HINTS
SET OL_NAME=DECODE(OL_NAME,’HINTSQL’,'ORIGINALSQL’,'ORIGINALSQL’,'HINTSQL’)
WHERE OL_NAME IN (‘ORIGINALSQL’,'HINTSQL’);
SET FOLLOWING PARAMETERS
“alter session set query_rewrite_enabled=true;
alter session set use_stored_outlines=true;”
NOTE THE INDEX SCAN WITHOUT ADDITION OF ANY HINT
select * from Joshi;
Query cannot be modified as it is hardcoded in an application or is generated by application code. “Query Tuning issues can often be alleviated by modification of the query in question, either to addhints or to change the query structure to avoid an issue. However in some cases the query cannot bemodified because it is hardcoded in an application or is generated by application code. Oracle provides the option of changing the execution plan for running queries, without changing thecode itself. This feature also allows us to insulate our application execution plans against anystructural changes or upgrades. This feature is known as Stored Outlines and the idea is to storethe execution plan in Oracle provided tables, which will later be referred to by the optimizer toexecute the queries, thus providing optimizer plan stability.Stored outlines are global and apply to all identical statements, regardless of the user firing it.

Under user SYS run $ORACLE_HOME/rdbms/admin/dbmsol.sql” PARAMETERS TO BE SET

“CREATE_STORED_OUTLINES   Setting this to TRUE or an appropriate category name will automatically enable creating and storingof outlines for every subsequent query fired. A DEFAULT category is used unless specified.

“”USE_STORED_OUTLINES This parameter enables the use of public stored outlines. Setting USE_STORED_OUTLINES to TRUE causesthe execution plan stored in the DEFAULT category to take effect. Set the parameter to a proper category name to explicitly use a different category.” “QUERY_REWRITE_ENABLED allows you to enable or disable query rewriting globally for the database”

Example:”EXAMPLE  1

select * from Joshi;

Execution Plan

———————————————————-

0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=15 Bytes=852)

1    0   TABLE ACCESS (FULL) OF ‘Joshi’ (Cost=1 Card=15 Bytes=852)”

CREATE OUTLINES AND THEN UPDATE THE OL$HINTS VIEW AS FOLLOWING : “CREATE OR REPLACE OUTLINE ORIGINALSQL ON select * from Joshi;

CREATE OR REPLACE OUTLINE HINTSQL ONselect /*+ index(Joshi) */  * from Joshi;

UPDATE OUTLN.OL$HINTS SET OL_NAME=DECODE(OL_NAME,’HINTSQL’,'ORIGINALSQL’,'ORIGINALSQL’,'HINTSQL’) WHERE OL_NAME IN (‘ORIGINALSQL’,'HINTSQL’); SET FOLLOWING PARAMETERS “alter session set query_rewrite_enabled=true;alter session set use_stored_outlines=true;”

NOTE THE INDEX SCAN WITHOUT ADDITION OF ANY HINT

select * from Joshi;


Friday, December 9, 2011

Rman Catalog Usefull Info ..


Q. What is Catalog database and How to Configure it ?

A. This is a separate database which contains catalog schema. You can use the same target database as the catalog database but its not at all recommended.

Q. How Many catalog database I can have ?

A.  You can have multiple catalog database for the same target database . But at a time you can connect to only 1 catalog database via RMAN. Its not recommended to have multiple catalog database.

Q. Is this mandatory to use catalog database ?

A.  No ! its a optional one.

Q. What is the advantage of catalog database ?

A.  Catalog database is a secondary storage of backup metadata. Its very useful in case you lost the current controlfile, as all the backup information are there in the catalog schema. Secondly from contolfile the older backup information are aged out depending upon the control_file_record_keep_time. RMAN catalog database mainten the history of data.

Q. What is the difference between catalog database & catalog schema ?

A.  Catalog database is like any other database which contains the RMAN catalog user’s schema.

Q. What happen if catalog database lost ?

 A.  Since catalog database is a option one there is no direct effect  of loss of catalog  database. Create  a new catalog database and register the target database with the newly createdcatalog one. All the backup information from the target database current controlfile will be updated to the catalog schema. If any backup information which is aged out from the target database then you need to manually catalog those backup pieces.

Saturday, November 19, 2011

IIT entrance exam 2012 forms online application form --

HI ,
Using below link we can fill the Online IIT entrance form .

http://www.iitg.ac.in/jee/


Let me knew for more detail ..


Thanks
Vinod Joshi

Synchronize a Gap on the Standby database in missing archived redo case


Synchronize a Gap on the Standby DB when the Archived Logs are Lost

Summary
Case Description: The archived logs are not present on the Standby DB and they are not available on the PROD Server,
so now the standby had lagged far behind the primary, many required archived logs to close the gap were removed and no backup of them was available.
In order to close the gap, we will perform an incremental backup that will contain all transactions since the last SCN recorded on the standby database.
Using this technique is convenient if the total amount of transactions that make the gap is less than the database size.

Action Items
In order to avoid this problem to happen in the future, we recommend the following action items
- Setup script for daily backup and cleanup of the recovery area
- Setup job to check for archivelog destination free space and executing the backup and cleanup script if required before the scheduled run.

Implementation Steps

Cancel Recovery on Standby
SQL> alter database recover managed standby database cancel;

Trying to recover on Standby
SQL> recover standby database;
ORA-00279: change 11021986 generated at 01/09/2011 11:39:03 needed for thread 1
ORA-00289: suggestion : /arch/ORACLE/ORADATA/SATI/ARCHIVE/1_205_674755717.ARC
ORA-00280: change 11021986 for thread 1 is in sequence #205

Check current_scn on Standby
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
11021980

Create an Incremental Backup from this SCN on the Primary DB
Z:\backup> rman target sys@PROD_PRIMARY
RMAN> backup incremental from scn 11021980 database tag 'FORSTANDBY' FORMAT '/BACKUP/FOR_STANDBY_%U';


Backup the Controlfile for ‘Standby’ on the Primary DB
RMAN> backup current controlfile for standby format '/BACKUP/FORSTDBYCTRL.bkp';

Transfer the Incremental Backup Sets from Primary DB to the Standby Server (Location = /Temp/Incr_Backup)
cd /BACKUP
copy FOR_STANDBY_*.*  \\STANDBY\ /TEMP/INCR_BACKUP
copy FORSTDBYCTRL.bkp  \\STANDBY\ /TEMP/INCR_BACKUP

Restore controlfile on the Standby
RMAN> RESTORE STANDBY CONTROLFILE FROM '/TEMP/INCR_BACKUP/FORSTDBYCTRL.BKP';

Catalog the Incremental Backups on the Standby Server
Note that for the catalog command to succeed you will need to move the backups to be within the Flash Recovery Area.
RMAN> catalog start with '/FRA/SATISTD/BACKUPSET';

Recover the Database and Cleanup Redologs on the Standby Server
RMAN> recover database noredo;
…
…
SQL> alter database flashback off;
SQL> alter database flashback on;
SQL> alter database recover managed standby database disconnect from session;

If more archived logs were created on the primary since the finish of the SCN based incremental backup then you can copy them over and recover the standby database using the command : “recover standby database;”

Enable the broker at both sites and check
When enabling the broker again it will take over the responsibility of managing the site and will resynchronize both sites
SQL> alter system set dg_broker_start=true scope=both;

Wednesday, October 12, 2011

07 Interesting Parameters in UNIX


07 Interesting Parameters in UNIX env..

$? –> Exit Status.

$# –> No: of arguments.

$* –> List of arguments.

$$ –> PID of current shell.

$! -–>PID of the last background process.

$- –> current shell settings.

$0 – $9 –-> Name of the command that is being executed.

Saturday, September 10, 2011

Difference between /bin, /sbin, /usr/bin and /usr/sbin

/bin contains all the essential binaries file that can be execute by local and other users
/sbin contains system files like useradd that can be exeute by root
local user has to use sudo to run these
/usr/bin , /usr/sbin contains non essential binaries e.g. office tools etc
these are parted to minimize size of root

Starting and Stopping Daemons with runlevel

The startup scripts I have been mentioning in the /etc/init.d directory govern the activation of daemons that were installed with some of your Linux packages. The commands to start and stop them are universal.
Starting a Daemon
If a startup script exists in the /etc/init.d directory, then its daemon can be started by specifying its filename followed by the keyword "start" as seen here:
root@u-joshi:~# /etc/init.d/apache start
 * Starting apache 1.3 web server...
   ...done.
root@u-joshi:~#

Stopping a Daemon

Daemons can be stopped by specifying its script filename followed by the keyword "stop":
root@u-joshi:~# /etc/init.d/apache stop
 * Stopping apache 1.3 web server...
   ...done.
root@u-joshi:~#

Restarting a Daemon

Daemons usually only read their configuration files when they are started, therefore if you edit the file, you have to restart the daemon for the new settings to become active. This can be done with the keyword "restart":
root@u-joshi:~# /etc/init.d/apache restart
 * Restarting apache 1.3 web server...
   ...done.
root@u-joshi:~#
chkconfig command can be used to adjust which applications start at each runlevel.
[root@joshi joshi ]# chkconfig --list
keytable 0:off 1:on  2:on  3:on 4:on  5:on 6:off
atd      0:off 1:off 2:off 3:on 4:on  5:on 6:off
syslog   0:off 1:off 2:on  3:on 4:on  5:on 6:off
gpm      0:off 1:off 2:on  3:on 4:on  5:on 6:off
kudzu    0:off 1:off 2:off 3:on 4:on  5:on 6:off
wlan     0:off 1:off 2:on  3:on 4:on  5:on 6:off
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
...
...
[root@joshi  joshi ]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@joshi joshi ]#
The chkconfig command can be used with grep to determine the run levels in which sendmail will run. Here we see it will run at levels 3 and 5. 

[root@joshi  joshi ]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@bigboy joshi ]#