High Availbility

OS & Virtualization

Tuesday, April 24, 2012

CRSCTL Commands CheatSheet

You can find below various commands which can be used to administer Oracle Clusterware using crsctl. This is for purpose of easy reference.
 
Relocate services
#srvctl status service -s opera -s slors
#srvctl relocate service -d opera -s slors -i opera3 -t opera1
 
Start Oracle Clusterware
#crsctl start crs
 
Stop Oracle Clusterware
#crsctl stop crs
 
Enable Oracle Clusterware
#crsctl enable crs
 
It enables automatic startup of Clusterware daemons
 
Disable Oracle Clusterware
#crsctl disable crs
It disables automatic startup of Clusterware daemons. This is useful when you are performing some
operations like OS patching and does not want clusterware to start the daemons automatically.
 
Checking Voting disk Location
$crsctl query css votedisk
0. 0 /dev/sda3
1. 0 /dev/sda5
2. 0 /dev/sda6
Located 3 voting disk(s).
Note: -Any command which just needs to query information can be run using oracle user. But anything which alters Oracle Clusterware requires root privileges.
Add Voting disk
#crsctl add css votedisk path
 
Remove Voting disk
#crsctl delete css votedisk path
 
Check CRS Status
$crsctl check crs
Cluster Synchronization Services appears healthy
Cluster Ready Services appears healthy
Event Manager appears healthy
You can also see particular daemon status
$crsctl check cssd
Cluster Synchronization Services appears healthy
$crsctl check crsd
Cluster Ready Services appears healthy
$crsctl check evmd
Event Manager appears healthy
You can also check Clusterware status on both the nodes using
$crsctl check cluster
prod01 ONLINE
prod02 ONLINE
 
Checking Oracle Clusterware Version
To determine software version (binary version of the software on a particular cluster node) use
$crsctl query crs softwareversion
Oracle Clusterware version on node [prod01] is [11.1.0.6.0]
For checking active version on cluster, use
$ crsctl query crs activeversion
Oracle Clusterware active version on the cluster is [11.1.0.6.0]
As per documentation, multiple versions are used while upgrading.
There are other options for CRSCTL too which can be seen using
$crsctl
Or
$crsctl help

Thursday, March 01, 2012

SQLServer commands

CommandPurposeSample Usage
sp_helpdbThis gives you information about all databases in the instance or specific information about one database.
  • sp_helpdb
  • sp_helpdb databasename
fn_virtualfilestatsThis command will show you the number of read and writes to a data file. Use sp_helpdb with the database name to see the logical file numbers for the data files and the database id.
  • SELECT * FROM :: fn_virtualfilestats(dabaseid, logicalfileid)
  • SELECT * FROM :: fn_virtualfilestats(1, 1)
fn_get_sql()Returns the text of the SQL statement for the specified SQL handle. This is similar to using DBCC INPUTBUFFER, but this command will show you additional information. This can also be embedded in a process easier then using the DBCC commandMSSQLTips additional info
  • DECLARE @Handle binary(20)
    SELECT @Handle = sql_handle FROM sysprocesses WHERE spid = 52 SELECT * FROM ::fn_get_sql(@Handle)
sp_lockThis command shows you all of the locks that the system is currently tracking This is similar to information you can see in Enterprise Manager.
  • sp_lock
  • sp_lock spid
  • sp_lock spid1, spid2
sp_helpThis command gives you information about the objects within a database. The command without an objectname will give you a list of all objects within the database.
  • sp_help
  • sp_help objectname
sp_who2Gives you process information similar to what you see when using Enterprise Manager.
  • sp_who2
  • sp_who2 spid
sp_helpindexGives you information about the indexes on a table as well as the columns used for the index.MSSQLTips additional info
  • sp_helpindex objectname
sp_spaceusedThis command shows you how much space has been allocated for the database (or if specified an object) and how much space is being used.
  • sp_spaceused
  • sp_spaceused objectname
DBCC CACHESTATSDisplays information about the objects currently in the buffer cache.
  • DBCC CACHESTATS
DBCC CHECKDBThis will check the allocation of all pages in the database as well as check for any integrity issues.
  • DBCC CHECKDB
DBCC CHECKTABLEThis will check the allocation of all pages for a specific table or index as well as check for any integrity issues.
  • DBCC CHECKTABLE (‘tableName’)
DBCC DBREINDEXThis command will reindex your table. If the indexname is left out then all indexes are rebuilt. If the fillfactor is set to 0 then this will use the original fillfactor when the table was created.MSSQLTips additional info
  • DBCC DBREINDEX (tablename, indexname, fillfactor)
  • DBCC DBREINDEX (authors, '', 70)
  • DBCC DBREINDEX ('pubs.dbo.authors', UPKCL_auidind, 80)
DBCC PROCCACHEThis command will show you information about the procedure cache and how much is being used. Spotlight will also show you this same information.
  • DBCC PROCCACHE
DBCC MEMORYSTATUSDisplays how the SQL Server buffer cache is divided up, including buffer activity.
  • DBCC MEMORYSTATUS
DBCC SHOWCONTIGThis command gives you information about how much space is used for a table and indexes. Information provided includes number of pages used as well as how fragmented the data is in the database.
  • DBCC SHOWCONTIG
  • DBCC SHOWCONTIG WITH ALL_INDEXES
  • DBCC SHOWCONTIG tablename
DBCC SHOW_STATISTICSThis will show how statistics are laid out for an index. You can see how distributed the data is and whether the index is really a good candidate or not.
  • DBCC SHOW_STATISTICS (tablename, indexname)
DBCC SHRINKFILEThis will allow you to shrink one of the database files. This is equivalent to doing a database shrink, but you can specify what file and the size to shrink it to. Use the sp_helpdb command along with the database name to see the actual file names used.MSSQLTips additional info
  • DBCC SHRINKFILE (filename, size in MB)
  • DBCC SHRINKFILE (DataFile, 1000)
DBCC SQLPERFThis command will show you much of the transaction logs are being used.
  • DBCC SQLPERF(LOGSPACE)
DBCC TRACEONThis command will turn on a trace flag to capture events in the error log. Trace Flag 1204 captures Deadlock information.
  • DBCC TRACEON(traceflag)
DBCC TRACEOFFThis command turns off a trace flag.

Saturday, January 28, 2012

Oracle incremental update using image copy

Explains the RMAN Image copy feature and incrementally updated backups New in Oracle 10G.

• Rman is configured with Recovery Catalog.
• Recovery Catalog Database Name-Orcl
• Database Name test is taken for demo
• Database Test is Running in no archive log mode
• Configured Backup location is 'D:\ORACLE\RMAN\ORA10G'
• During the first and second run of the backup scripts I made some changes in the Database. Also during the second and the third run I made some changes in the Database.


Expanded Image Copying Features: A standard RMAN backup set contains one or more backup pieces, and each of these pieces consists of the data blocks for a particular datafile stored in a special compressed format. When a datafile needs to be restored, therefore, the entire datafile essentially needs to be recreated from the blocks present in the backup piece.


An image copy of a datafile, on the other hand, is much faster to restore because the physical structure of the datafile already exists. Oracle 10g now permit image copies to be created at the database, tablespace, or datafile level through the new RMAN directive BACKUP AS COPY. For example, here is a command script to create image copies for all datafiles in the entire database:
Backup Procedure
Step 1 : Create a image copy of full database
RUN {
ALLOCATE CHANNEL dbkp1 DEVICE TYPE DISK FORMAT 'D:\oracle\rman\ora10G\U%';
BACKUP AS COPY DATABASE; }

Step 2 : Backup incrementally and restore to the image copy
RUN {
# Roll forward any available changes to image copy files
# From the previous set of incremental Level 1 backups
RECOVER COPY OF DATABASE WITH TAG 'cool';
# Create incremental level 1 backup of all datafiles in the database
# For roll-forward application against image copies
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'cool' DATABASE; }

Restore/recovery procedure
In case of a disaster you can now tell rman to just change the locations of the datafiles in the controlfile to the image copies by issuing the following:
RMAN> alter database mount;
RMAN> switch database to copy;

If you want to restore the database
RMAN > restore database;
RMAN > recover database;

 

DBMS SCHEDULER

DBMS SCHEDULER is a more sophisticated job scheduler introduced in Oracle 10g. The older job scheduler, DBMS_JOB, is still available, is easier to use in simple cases
Make sure the OracleJobScheduler Service is started.
Create a job
BEGIN
   DBMS_SCHEDULER.CREATE_JOB (
   job_name => 'myjob',
   job_type => 'EXECUTABLE',
   job_action => 'd:\oracle\script\vng.bat',
   repeat_interval => 'FREQ=MINUTELY',
   enabled => TRUE );
END;

Remove a job
EXEC DBMS_SCHEDULER.DROP_JOB('myjob');
Change job attributes
Examples:
EXEC DBMS_SCHEDULER.SET_ATTRIBUTE('WEEKNIGHT_WINDOW', 'duration', '+000 06:00:00');
BEGIN
   DBMS_SCHEDULER.SET_ATTRIBUTE ('WEEKNIGHT_WINDOW',    'repeat_interval', 'freq=daily;byday=MON, TUE, WED, THU, FRI;byhour=0;byminute=0;bysecond=0');
END;/
Enable
/
Disable a job
BEGIN
   DBMS_SCHEDULER.ENABLE('myjob');
END;

BEGIN
   DBMS_SCHEDULER.DISABLE('myjob');
END;

Monitoring jobs
SELECT * FROM dba_scheduler_jobs WHERE job_name = 'myjob';
SELECT * FROM dba_scheduler_job_log WHERE job_name = 'myjob';

Use user_scheduler_jobs and user_scheduler_job_log to only see jobs that belong to your user (current schema).

Friday, January 20, 2012

Oracle image copy

With Oracle 10g R2 we can recover datafile copies like we recover the real datafiles.This gives us the oportunity to recover the entire database without having to restore it from backup first.Which of course saves very valuable time in case of a disaster.

Backup Procedure
Step 1 : Create a image copy of full database
RUN {
ALLOCATE CHANNEL dbkp1 DEVICE TYPE DISK FORMAT 'D:\oracle\rman\ora10G\U%';
BACKUP AS COPY DATABASE; }

Step 2 : Backup incrementally and restore to the image copy
RUN {
# Roll forward any available changes to image copy files
# From the previous set of incremental Level 1 backups
RECOVER COPY OF DATABASE WITH TAG 'cool';
# Create incremental level 1 backup of all datafiles in the database
# For roll-forward application against image copies
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'cool' DATABASE; }

Restore/recovery procedure
In case of a disaster you can now tell rman to just change the locations of the datafiles in the controlfile to the image copies by issuing the following:
RMAN> alter database mount;
RMAN>switch database to copy;

If you want to restore the database
RMAN > restore database;
RMAN > recover database;

Investigating high redo archive generation

If you have ASH, you can use it to find the sessions and queries that waited the most for “log file sync” event. I found that this has some correlation with the worse redo generators.view sourceprint?

  1. find the sessions and queries causing most redo and when it happened




select SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*)
from V$ACTIVE_SESSION_HISTORY
where event like 'log file sync'
AND SESSION_ID=506
group by SESSION_ID,user_id,sql_id,round(sample_time,'hh')
order by count(*) desc


 



  1. you can look the the SQL itself by: 



select * from DBA_HIST_SQLTEXT
where sql_id='dwbbdanhf7p4a'

Another ways from Oracle metalink is by checking block_changes

SELECT s.sid, s.serial#, s.username, s.program, i.block_changes
FROM v$session s, v$sess_io i
WHERE s.sid = i.sid
ORDER BY 5 , 1, 2, 3, 4;








you can also check using this script if you are using 10g and above








SELECT dhso.object_name, sum(db_block_changes_delta)
FROM dba_hist_seg_stat dhss, dba_hist_seg_stat_obj dhso, dba_hist_snapshot dhs
WHERE dhs.snap_id = dhss.snap_id
AND dhs.instance_number = dhss.instance_number
AND dhss.obj# = dhso.obj# AND dhss.dataobj# = dhso.dataobj#
AND begin_interval_time BETWEEN to_date(’2012_01_19 18',’YYYY_MM_DD HH24')
AND to_date(’2012_01_19 19',’YYYY_MM_DD HH24')
GROUP BY dhso.object_name order by sum(db_block_changes_delta) desc

SELECT distinct dbms_lob.substr(sql_text,4000,1)
FROM dba_hist_sqlstat dhss,
dba_hist_snapshot dhs,
dba_hist_sqltext dhst
WHERE upper(dhst.sql_text) LIKE ‘%INT_UPLOAD_STATUS%’
AND dhss.snap_id=dhs.snap_id
AND dhss.instance_Number=dhs.instance_number
AND dhss.sql_id = dhst.sql_id and rownum<2;






Tuesday, August 17, 2010

VirtualBox Commands

Using VirtualBox you can run multiple Virtual Machines (VMs) on a single server, allowing you to run both RAC nodes on a single machine. Here are some of the useful command to create a virtual SAN storage.

To set a UUID of a hard drive run this
> VBoxManage internalcommands setvdiuuid disk2.vdi

Create the disks and associate them with VirtualBox as virtual media.
> VBoxManage createhd --filename asm1.vdi --size 5120 --format VDI --variant Fixed
Connect them to the VM.
> VBoxManage storageattach ol6-112-rac1 --storagectl "SATA" --port 1 --device 0 --type hdd \
    --medium asm1.vdi --mtype shareable


To manually clone a virtual disk
> VBoxManage clonehd /u01/VirtualBox/ol6-112-rac1/ol6-112-rac1.vdi /u03/VirtualBox/ol6-112-rac2/ol6-112-rac2.vdi

Friday, July 30, 2010

Restoring a 32Bit RMAN backup on 64Bit Operating System

Restoring a 32Bit RMAN backup on 64Bit Operating System

It is possible to restore RMAN backups taken on 32 bit operating system (with 32 bit oracle binaries) to a 64 bit operating system (with 64 bit oracle binaries). But it is preferable to keep the same bit version, but as long as the same operating system platform is maintained the common consensus is this will work.

If you will be running the 64-bit database against the 32-bit binary files or vice versa, after the recovery has ended the database bit version must be converted using utlirp.sql. The utlirp.sql script recompiles existing PL/SQL modules in the format required by the new database. If the version does not include a call to
utlrp, then you must manually run utlrp.sql to recompile invalid objects.

See this note for details on switching between bit sizes:

Note 62290.1 Changing between 32-bit and 64-bit Word Sizes

Example :
======

Things to do on 32 bit server :
+ Take a full backup of database including archivelogs on 32 bit server



 
RMAN> run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database plus archivelog;
backup current controlfile;
}








Things to do on 64 bit server :

+ Make the backups available on 64 bit server
+ Create the pfile or copy the pfile from 32 bit server
+ Startup nomount the instance on the 64 bit server.

+ connect to rman and set the dbid



 
$ rman target / nocatalog
RMAN> set dbid=<dbid from 32 server>;

+ Restore the controlfile
RMAN> restore controlfile from '/disk1/backup/backup_piece_name';
RMAN> alter database mount;
RMAN> restore database;






+ Identify the archivelog till you want to do the recovery and check whether you have all the backups.



 
RMAN> run
{
set until sequence xxxx;
recover database;
}

RMAN> exit

+ Migrating to 64 bit
SQL> recover database until cancel using backup controlfile;
cancel
SQL> alter database open resetlogs migrate;
SQL> @ ?/rdbms/admin/utlirp.sql
Now you must restart the database and explicitly invoke utlrp.sql to recompile invalid objects.
SQL> shutdown immediate;
SQL> startup;
SQL> @ ?/rdbms/admin/utlrp.sql

SQL> shutdown immediate;
SQL> startup






The database is now opened to use.

Tuesday, July 13, 2010

Snapshot standby in Oracle 10g

Snapshot standby allow the standby database to open for testing, reporting prupose. You can revert back the transactions to continue in standby mode. You can also use snapshot standby in Oracle 10g.  11g reduces these steps making this a feature they call the “SNAPSHOT DATABASE”.
Steps:1.Set Flash Recovery Area parameters
2.Create a guranteed restore point
3.Activate standby database
4.Perform read/write testing
5.Revert to original standby
1.Set Flash Recovery Area parameters

 SQL> alter system set db_recovery_file_dest_size=2G;

SQL> alter system set db_recovery_file_dest='D:\oracle\product\10.2.0\fra';

2.Create a guranteed restore pointto revert to when you need to return to the original state.



SQL> create restore point pre_activ_snap guarantee flashback database;


SQL> select name, time, storage_size,GUARANTEE_FLASHBACK_DATABASE from V$restore_point;

NAME TIME STORAGE_SIZE GUA
-------------------------------------------------- -------------------------------- ------------ ---
PRE_ACTIV_SNAP 20-MAR-10 07.59.35.000000000 PM 8192000 YES









3.Activate the standby database


SQL> alter database activate standby database;

SQL> select name, open_mode, controlfile_type from V$database;

NAME OPEN_MODE CONTROL
-------------------------------------------------- -------------------- -------
ORCL MOUNTED CURRENT

SQL> alter database open;

SQL> select name, open_mode, controlfile_type from V$database;

NAME OPEN_MODE CONTROL
-------------------------------------------------- -------------------- -------
ORCL READ WRITE CURRENT






Now the standby database is in READ/WRITE mode after the activation.



 
PRMY> ALTER SYSTEM ARCHIVE LOG CURRENT;
PRMY> ALTER SYSTEM SET DG_BROKER_START=FALSE;
PRMY> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=DEFER;







NOW you can use the physical standby safely for testing purposes, it is a fully functional database with data the same as production as of a certain point in time, no new data will be added…remember your Recovery Time Objective.

When testing is over, Revert….back into a physical standby.



 
STBY> STARTUP MOUNT FORCE;
STBY> FLASHBACK DATABASE TO RESTORE POINT HOTFIX1;
STBY> ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
STBY> STARTUP MOUNT FORCE;

STBY> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;








(*using REAL-TIME APPLY)

Some useful SQL commands



 
SELECT NAME, SCN, TIME, DATABASE_INCARNATION#, GUARANTEE_FLASHBACK_DATABASE,STORAGE_SIZE
FROM V$RESTORE_POINT;

select * from v$flash_recovery_area_usage;








Thursday, February 26, 2009

SimpleCheck - Oracle diag checking utilties

This program provide a convenient way to check for the status of Oracle database. You can easily find out which datafiles is OFFLINE, which datafiles need recoveries, what many invalid objects in the database, etc. You do not need to remember complex SQL statements to retrieve those information.

This program like all our previous program, it does not requires to be install. If you are running on windows 2003 server, you have all the necessary DDL to run it.

Features
  • Show Hard disk space
  • Show Oracle status "mount, open", version
  • SHow the location of alert.log, archive log
  • Show datafiles which needs recoveries, offline
  • Show how many objects are invalid
  • Show the amount of tablespace free space.
Updates
  • Display a list of tables, last analyzed date, number of rows in a schema
  • Display what privileges a schema owner has
Show a current status of database, Hard disk space, alert_log location.
 
List the tablespace space

 

 

List schema information such as tables, privileges, last analyzed date, etc

Download
Get it from CNET Download.com!

Friday, December 19, 2008

How to Run a Batch File Before Logging on to Your Computer

Windows server can be configured to run a startup script that is a batch file, VB script. The AutoExnt utility is included in the Resource Kit so that this functionality is available.


The AutoExNT service permits an administrator to configure a Windows 2000-based computer to run a custom batch file when first starting the computer. Also, a user or administrator is not required to be logged on at the time this custom batch file runs.

http://support.microsoft.com/kb/q243486/

Installing the AutoExNT Service

  1. Using a text editor (such as Notepad), create a batch file named Autoexnt.bat and include the commands you want to run at startup in this file.
  2. Copy the Autoexnt.bat file you just created, in addition to the Autoexnt.exe, Servmess.dll, and Instexnt.exe files located in the Resource Kit CD-ROM to the %SystemRoot%\System32 folder on your computer.
  3. At a command prompt, type instexnt install, and then press ENTER.

Tuesday, December 02, 2008

simpleBack - GUI Oracle Rman Backup tool

Update ** VRMAN backup tools
New version of oracle rman backup. Support compressed backup, controlfile backup and archivelog backup.



SimpleBack is a GUI for Oracle Rman backup.

Tradtionally backing up Oracle database is difficult as you either require to know Rman command or purchase 3rd party software. You can use 3rd party software like Veritas or Arcserve bu they are not cheap.

SimpleBack change it all. Just select the option from the radio button and click run. It will generate rman scripts and backup your oracle database. It's that easy! This is a free tool for all to share. Tested on Oracle 10g. (should work on Oracle 9i)

Option
  • Backup Full : Backup the whole database
  • List Backup : List all the backups (including datbase, archivelog and controlfile)
  • Delete Backup : Delete all the obsolete backup , based on the retention policy
  • Restore Full : Perform a complete recovery.
FAQ
  • Where does the backup location set?
    Default location of Oracle 10g is on flash_recovery_area. You can manually set it using Rman command
  • Why can't I do a backup?
    Did you set your database in archivelog mode? Backup are perform using online backup, thus you need to set it to archivelog mode.
  • How do I change the retention policy?
    You have to change it using the rman command. By default it is set to 1 day.
download
https://app.box.com/s/1mdt3shdga43cks7gbtl

simpleBack - GUI Oracle Rman Backup tool

SimpleBack is a GUI for Oracle Rman backup. Just select the option from the radio button and click run. It will generate rman scripts and backup your oracle database. It's that easy! This is a free tool for all to share. Tested on Oracle 10g. (should work on Oracle 9i)

Tuesday, November 04, 2008

Oracle Application Server Troublshooting

Oracle Application Server 10g offers a comprehensive solution for developing, integrating, and deploying your enterprise's applications, portals, and Web services.

Each application server can support up to 70 concurrent users.

Oracle10gappR2AScontrol
This service is used to give access to remote administration of the app server via a web browser interface on port 1810. While this service is running, you can point a browser to the URL
http://[appserver]:1810 and you will be asked to log in. The default login and password for that connection are ias_admin‟

Oracle10gappR2ProcessManager
This is the master service that controls all the other services needed by the application server. This service is more of a shell for the other services such as the HTTP_Listener, the OC4J servers, etc. To monitor what this service is actually running, you use the „opmnctl‟ utility from the command line.

OPMNCTL Utility
The opmnctl utility is located on the application server in the \oracle\10gappr2\opmn\bin directory. This utility can be used to view what processes are currently being managed by the Oracle10gappr2ProcessManager service
.

Report Queue Manager
Print jobs processed from thin-client sessions can be managed using the Oracle Report Queue Manager utility. From any workstation access the URL -
http://[appserver]/reports/rwservlet/showjobs?server=rep[appserver]orcl -

Other user commands

> rwdiag -findall
> rwserver server=rep[servername]

Tuesday, September 30, 2008

Boot and run Linux from a USB flash memory stick

Boot and run Linux from a USB flash memory stick


Carry a portable Linux version with you on a USB flash pen drive. Easily bring your portable desktop with you wherever you go. I have managed to do so, so can you.

USB Feather Linux Prerequisites:

  • 128MB or larger USB pen drive
  • Feather Linux
  • HP USB tool (for formatting the stick)
  • Syslinux

The Feather USB Installation Process:

  1. Download the HP USB tool and format your stick with the tool using a FAT file system.
  2. Download the Feather Linux zip file.
  3. Extract the files from feather-0.7.4-usb.zip to your USB stick.
  4. Download and extract syslinux.zip to a directory on your computer.
  5. Run the command prompt in windows (start/run/cmd) and CD to the syslinux directory. Once there simply type syslinux.exe F: (F: being the example drive letter of the USB stick in this system)
    Reboot your PC, go into your system BIOS and set your boot order to boot from any selectable USB device. (example USB_ZIP or USB_HDD)
    Save your BIOS settings. On the next reboot, you should have a sucessful launch of Feather Linux from USB

Sunday, August 24, 2008

Understanding Statspack

This section shows a great deal of information, in a very small amount of space. We can see how much REDO is generated on average every second and for every transaction. Here, I can see that I generate about 5 to 6 KB of redo per second. My average transaction generates just 13 KB of redo. The next bit of information has to do with logical and physical I/O. I can see here that about 1 percent of my logical reads resulted in physical I/O – that is pretty good. I can also see that on average, my transactions perform almost 4,000 logical reads. Whether that is high or not depends on the type of system you have.
In my case, there were some large background jobs executing, so a high read count is acceptable.
Now for the really important information: my parse-related statistics. Here I can see that I do about 16 parses per second and about 0.17 of those are hard parses (SQL that never existed before). Every six
seconds or so, my system is parsing some bit of SQL for the very first time. That is not bad. However, I would prefer a count of zero in this column in a finely tuned system that has been running for a couple of days. All SQL should be in the shared pool after some point in time.

The next section in the above shows us some interesting numbers. The % Blocks Changed per Read shows us that in this case, 99 percent of the logical reads we do are for blocks that are only read, not updated. This system updates only about 1 percent of the blocks retrieved. The Recursive Call % is very high – over 97 percent. This does not mean that 97 percent of the SQL executed on my system is due to 'space management' or parsing. If you recall from our analysis of the raw trace file earlier from SQL_TRACE, SQL executed from PL/SQL is considered 'recursive SQL'. On my system, virtually all work is performed using PL/SQL, other than mod_plsql (an Apache web server module) and an occasional background job, everything is written in PL/SQL on my system. I would be surprised if the Recursive Call % were low in this case.
The percentage of transactions that rolled back (Rollback per transaction %)is very low, and that is a good thing. Rolling back is extremely expensive. First, we did the work, which was expensive.
Then, we undid the work and again, this is expensive. We did a lot of work for nothing. If you find that most of your transactions roll back, you are spending too much time doing work and then immediately undoing it. You should investigate why you roll back so much, and how you can rework your application to avoid that. On the system reported on, one out of every 345 transactions resulted in a
rollback – this is acceptable.

In my mind, the most important ratios are the parse ratios – they get my attention immediately. The soft parse ratio is the ratio of how many soft versus hard parses we do. 99 percent of the parses on this system are soft parses (reused from the shared pool). That is good. If we see a low soft parse ratio, this would be indicative of a system that did not use bind variables. I would expect to see a very high ratio in this field regardless of tools or techniques used. A low number means you are wasting resources and introducing contention. The next number to look at is the Parse CPU to Parse Elapsd. Here, I show about 88 percent. This is a little low; I should work on that. In this case for every CPU second spent parsing we spent about 1.13 seconds wall clock time. This means we spent some time waiting for a resource – if the ratio was 100 percent, it would imply CPU time was equal to elapsed time and we processed without any waits. Lastly, when we look at Non-Parse CPU, this is a comparison of time spent doing real work versus time spent parsing queries. The report computes this ratio with round(100*(1- PARSE_CPU/TOT_CPU), 2). If the TOT_CPU is very high compared to the PARSE_CPU (as it should be), this ratio will be very near 100 percent, as mine is. This is good, and indicates most of the work performed by the computer was work done to execute the queries, and not to parse them.
All in all, in looking at the above section, my recommendation would be to reduce the hard parses even further. There obviously are a couple of statements still not using bind variables somewhere in the system (every six seconds a new query is introduced). This in turn would reduce the overall number of parses done because a hard parse has to perform a lot of recursive SQL itself. By simply removing a single hard parse call, we'll reduce the number of soft parses we perform as well. Everything else in that section looked acceptable. This first section we just reviewed is my favorite part of the StatsPack report, at a glance it gives a good overview of the relative 'health' of your system. Now, onto the rest of the report:

This little snippet gives us some insight into our shared pool utilization. The details shown above are:
❑ Memory Usage – The percentage of the shared pool in use. This number should stabilize in mid-70 percent to less than 90 percent range over time. If the percentage is too low, you are wasting memory. If the percentage is too high, you are aging components out of the shared pool, this will cause SQL to be hard parsed if it is executed again. In a right-sized system, your shared pool usage will stay in the 75 percent to less than 90 percent range.

❑ SQL with executions>1 – This is a measure of how many SQL statements were found in
the shared pool that have been executed more than once. This number must be considered carefully in a system that tends to run in cycles, where a different set of SQL is executed during one part of the day versus another (for example, OLTP during the day, DSS at night).
You'll have a bunch of SQL statements in your shared pool during the observed time that were not executed, only because the processes that would execute them did not run during the period of observation. Only if your system runs the same working set of SQL continuously will this number be near 100 percent. Here I show that almost 80 percent of the SQL in my shared pool was used more than once in the 13 minute observation window. The remaining 20 percent was there already probably – my system just had no cause to execute it.

❑ Memory for SQL w/exec>1 – This is a measure of how much of the memory the SQL you
used frequently consumes, compared to the SQL you did not use frequently. This number will in general be very close to the percentage of SQL with executions greater than one, unless you have some queries that take an inordinate amount of memory. The usefulness of this particular value is questionable.
So, in general you would like to see about 75 to 85 percent of the shared pool being utilized over time in a steady state. The percentage of SQL with executions greater than one should be near 100 percent if the time window for the StatsPack report is big enough to cover all of your cycles. This is one statistic that is affected by the duration of time between the observations. You would expect it to increase as the amount of time between observations increases.

Friday, July 04, 2008

How to create PLSQL webservice

How to create PLSQL webservice

Required Software

Generating webservice ear

  1. Create a config.xml file
    class="com.evermind.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/OracleCoreDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="store"
    password="store"
    url="jdbc:oracle:thin:@localhost:1521:ORCL" inactivity-timeout="30"/>

  2. Run the following command
    set JAVA_HOME=c:\j2sdk1.4.2_06set
    ORACLE_HOME=c:\oracle\oc4j
    set CLASSPATH=.;%ORACLE_HOME%\webservices\lib\wsdl.jar;%ORACLE_HOME%\lib\xmlparserv2.jar;%ORACLE_HOME%\soap\lib\soap.jar
    call %JAVA_HOME%\bin\java -jar %ORACLE_HOME%\webservices\lib\WebServicesAssembler.jar -config .\config.xml

Thursday, June 26, 2008

Flash Recovery usiing Image Copy

Flash Recovery using Image Copy
Image Copy
Oracle RMAN image copies are exact copies of the datafiles, with all the blocks—used or not. Oracle RMAN takes this image copy while the database is up and running, and the database need not be put into any special mode.
Here is how to make an Oracle RMAN image copy backup:
run {
   backup as copy
   database; }

Instant Recovery
Image copies in the FRA become truly useful when you need an "instant recovery." Remember that these image copies are copies of the datafiles—a fact recorded in the Oracle RMAN catalog and the control file. In case of a disaster, you don't need to restore the file; you can use the copy as the principal datafile immediately.
Here is the description of the recovery process, assuming that the USERS tablespace has been damaged: First, check the file ID (number) and name of the datafile of the tablespace. The output is shown in vertical format:
select file_id, file_name  from dba_data_files 
where tablespace_name  = 'USERS'; 
FILE_ID : 4 NAME    : /home/oracle/oradata/PRODB2/users01.dbf 
RMAN> sql 'alter tablespace users offline';
 sql statement: alter tablespace users offline 
RMAN> switch datafile 4 to copy;
 datafile 4 switched to datafile copy "/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf" 
RMAN> recover datafile 4;
 Starting recover at 26-SEP-06 using channel ORA_DISK_1
 starting media recovery media recovery complete,
 elapsed time: 00:00:03
 Finished recover at 26-SEP-06  
RMAN> sql 'alter tablespace users online';
 sql statement: alter tablespace users online
 
Switchback 

Even though the datafile has been quickly brought online to minimize downtime, it is now in the backup location, which may be on slower disks than what the main database is on. You may not want to run the database with the datafile at this location for long; you would typically want to move the datafile back to the original location—/home/oracle/oradata/PRODB2/—as soon as it becomes available. You can use Oracle RMAN to accomplish this. Here is a summary of the steps:
1. Make an image copy of the datafile at the original location. 2. Take the tablespace offline. 3. Switch the datafile to the "copy" (however, in this case, the "copy" is at the original location). 4. Recover the tablespace. 5. Place the tablespace online.
These steps are presented in Listing 4. After the switchover, you can make sure the datafile is back in its original location:
select name from v$datafile  where file# = 4;
   NAME ---------------------------------------
 /home/oracle/oradata/PRODB2/users01.dbf
 
RMAN> backup as copy datafile 4 format '/home/oracle/oradata/PRODB2/users01.dbf';
   Starting backup at 27-SEP-06 using channel
 ORA_DISK_1 channel ORA_DISK_1: starting datafile
 copy input datafile fno=00004 name=/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf
 output filename=/home/oracle/oradata/PRODB2/users01.dbf
 tag=TAG20060927T103710 recid=45 stamp=602246230 channel
 ORA_DISK_1: datafile copy complete,
 elapsed time: 00:00:01
 Finished backup at 27-SEP-06
   Starting Control File Autobackup at 27-SEP-06 piece handle=/home/oracle/FRA/PRODB2/autobackup/2006_09_27/ o1_mf_n_602246232_2ko34s42_.bkp comment=NONE 
Finished Control File Autobackup at 27-SEP-06 RMAN> sql 'alter tablespace users offline'; ... 
RMAN> switch datafile 4 to copy;   datafile 4 switched to datafile copy "/home/oracle/oradata/PRODB2/users01.dbf"  
RMAN> recover datafile 4; ... 
RMAN> sql 'alter tablespace users online'; ... 
 
In case of a failure, you save valuable time by quickly using the image copy of the datafile in the FRA, and there is no need to restore it first. The same concept can be applied to the entire database as well. If the original location of all the datafiles is damaged, you can easily switch the entire database to the copy stored in the FRA. To switch to the FRA copy, issue the following, which directs the whole database to use all the latest image copies in the FRA location as its datafiles: 
 
RMAN> switch database to copy;  
 


Recover database after disk loss

Control Files

 
Normally, we have multiplexing of controlfiles and they are expected to be placed in different disks.
 
If one or more controlfile is/are lost,mount will fail as shown below:
....
ORA-00205: error in identifying controlfile, check alert log for more info
 
**If at least one copy of the controlfile is not affected by the disk failure, 
   When the database is shutdown cleanly:
   (a) Copy a good copy of the controlfile to the missing location
   (b) Start the database 
 
   Alternatively, remove the lost control file location specified in the nit parameter control_files and start the database.
 
   **If all copies of the controlfile are lost due to the disk failure, then: Check for a backup controlfile. Backup controlfile is normally taken using either of the following commands:
   (a) SQL> alter database backup controlfile to '/backup/control.ctl';
    -- This would have created a binary backup of the current controlfile --
 
    -->If the backup was done in binary format as mentioned above, restore the file to the lost controlfile locations using OS copying utilities.
    --> SQL> startup mount;
    --> SQL> recover database using backup controlfile;
    --> SQL> alter database open;
 
   (b) SQL> alter database backup controlfile to trace;
    -- This would have created a readable trace file containing create controlfile script --
 
    --> Edit the trace file created (check user_dump_dest for the location) and retain the SQL commands alone. Save this to a file say cr_ctrl.sql
è      Run the script
 

Redo logs

In normal cases, we would not have backups of online redo log files. But the inactive logfile changes could already have been checkpointed on the datafiles and even archive log files may be available.
 
SQL> 
     ORA-00313: open failed for members of log group 1 of thread 1
     ORA-00312: online log 1 thread 1: '/ORACLE/ORADATA/H817/REDO01.LOG'
     ORA-27041: unable to open file
     OSD-04002: unable to open file
     O/S-Error: (OS 2) The system cannot find the file specified.
 
** Verify if the lost redolog file is Current or not.
     SQL> select * from v$log;
     SQL> select * from v$logfile; 
 
     --> If the lost redo log is an Inactive logfile, you can clear the logfile:
 
     SQL> alter database clear logfile GROUP 1;
 
     Alternatively, you can drop the logfile if you have atleast two other logfiles:
     SQL> alter database drop logfile group 1;
     
     --> If the logfile is the Current logfile, then do the following:
     SQL> recover database until cancel;
     SQL>alter database open resetlogs;
 
If the database is in noarchivelog mode and if ORA-1547, ORA-1194 and ORA-1110 errors occur, then you would have restore from an old backup and start the database.
 
Note that all redo log maintenance operations are done in the database mount state
    

Parameter file

This is not a major loss and can be easily restored. Options are:
1.       If there is a backup, restore the file
2.       If there is no backup, copy sample file or create a new file and add the required parameters. Ensure that the parameters db_name, control_files,vdb_block_size, compatible are set correctly
3.    If the spfile is lost, you can create it from the init parameter file

Flash Recovery using Image Copy

Flash Recovery using Image Copy


Image Copy
Oracle RMAN image copies are exact copies of the datafiles, with all the blocks—used or not. Oracle RMAN takes this image copy while the database is up and running, and the database need not be put into any special mode.
Here is how to make an Oracle RMAN image copy backup:



 
run {
   backup as copy
   database; }
 



Instant Recovery 

Image copies in the FRA become truly useful when you need an "instant recovery." Remember that these image copies are copies of the datafiles—a fact recorded in the Oracle RMAN catalog and the control file. In case of a disaster, you don't need to restore the file; you can use the copy as the principal datafile immediately.  
Here is the description of the recovery process, assuming that the USERS tablespace has been damaged: First, check the file ID (number) and name of the datafile of the tablespace. The output is shown in vertical format:





 select file_id, file_name from dba_data_files where tablespace_name = 'USERS';
FILE_ID : 4 NAME : /home/oracle/oradata/PRODB2/ users01.dbf








 RMAN> sql 'alter tablespace users offline';
sql statement: alter tablespace users offline
RMAN> switch datafile 4 to copy;
datafile 4 switched to datafile copy "/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf"
RMAN> recover datafile 4;
Starting recover at 26-SEP-06 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:03 Finished recover at 26-SEP-06
RMAN> sql 'alter tablespace users online'; sql statement: alter tablespace users online



 
Switchback 

Even though the datafile has been quickly brought online to minimize downtime, it is now in the backup location, which may be on slower disks than what the main database is on. You may not want to run the database with the datafile at this location for long; you would typically want to move the datafile back to the original location—/home/oracle/oradata/PRODB2/—as soon as it becomes available. You can use Oracle RMAN to accomplish this. Here is a summary of the steps: 

1. Make an image copy of the datafile at the original location.
2. Take the tablespace offline.
3. Switch the datafile to the "copy" (however, in this case, the "copy" is at the original location).
4. Recover the tablespace.
5. Place the tablespace online. 

These steps are presented in Listing 4. After the switchover, you can make sure the datafile is back in its original location: 

select name from v$datafile  where file# = 4;
NAME ---------------------------------------
/home/oracle/oradata/PRODB2/users01.dbf
 
 
RMAN> backup as copy datafile 4 format '/home/oracle/oradata/PRODB2/users01.dbf';
Starting backup at 27-SEP-06 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile fno=00004 name=/home/oracle/FRA/PRODB2/datafile/o1_mf_users_2kmqr57t_.dbf output filename=/home/oracle/oradata/PRODB2/users01.dbf tag=TAG20060927T103710 recid=45 stamp=602246230 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 27-SEP-06 Starting Control File Autobackup at 27-SEP-06 piece handle=/home/oracle/FRA/PRODB2/autobackup/2006_09_27/ o1_mf_n_602246232_2ko34s42_.bkp comment=NONE Finished Control File Autobackup at 27-SEP-06 RMAN> sql 'alter tablespace users offline'; ... RMAN> switch datafile 4 to copy; datafile 4 switched to datafile copy "/home/oracle/oradata/PRODB2/users01.dbf" RMAN> recover datafile 4; ... RMAN> sql 'alter tablespace users online'; ...
In case of a failure, you save valuable time by quickly using the image copy of the datafile in the FRA, and there is no need to restore it first. The same concept can be applied to the entire database as well. If the original location of all the datafiles is damaged, you can easily switch the entire database to the copy stored in the FRA. To switch to the FRA copy, issue the following, which directs the whole database to use all the latest image copies in the FRA location as its datafiles: 
RMAN> switch database to copy;  



Wednesday, June 18, 2008

All About Explain Plan

Introduction

The EXPLAIN PLAN statement displays execution plans chosen by the Oracle optimizer for SELECT, UPDATE, INSERT, and DELETE statements. A statement's execution plan is the sequence of operations Oracle performs to run the statement.

Using V$SQL_PLAN

In addition to running the EXPLAIN PLAN command and displaying the plan, you can use the V$SQL_PLAN views to display the execution plan of a SQL statement:

 
Using Explain Plan
Steps
  • EXPLAIN PLAN FOR   SELECT last_name FROM employees;
  • SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());

About Autotrace

  1. cd $oracle_home/rdbms/admin

  2. log into sqlplus as system

  3. run SQL> @utlxplan

  4. run SQL> create public synonym plan_table for plan_table

  5. run SQL> grant all on plan_table to public

  6. exit sqlplus and cd $oracle_home/sqlplus/admin

  7. log into sqlplus as SYS

  8. run SQL> @plustrce

  9. run SQL> grant plustrace to public

 

You can control the report by setting the AUTOTRACE system variable.
  • SET AUTOTRACE ON EXPLAIN - The AUTOTRACE report shows only the optimizer execution path. 
  • SET AUTOTRACE ON STATISTICS - The AUTOTRACE report shows only the SQL statement execution statistics.  
  • SET AUTOTRACE ON  - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.  
  • SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any. 


Wednesday, June 11, 2008

How to bypass Oracle installer check

Is there a way to get Oracle10g installed on other linux not specified in the pre-requities list?

<< ./runInstaller Starting Oracle Universal Installer... Checking installer requirements... Checking operating system version: must be redhat-2.1, UnitedLinux-1.0 or redhat-3 Failed <<<< ./runInstaller -ignoreSysPrereqs