30
Dec
11

Estimate the size of the index before its creation

Before you create an index, you can estimate how much space it will take via the
DBMS_SPACE.CREATE_INDEX_COST
SQL> set serverout on
SQL> exec dbms_stats.gather_table_stats(user,’CUST’);
SQL> variable used_bytes number
SQL> variable alloc_bytes number
SQL> exec dbms_space.create_index_cost( ‘create index cust_idx2 on cust(first_name)’, –
:used_bytes, :alloc_bytes );
SQL> print :used_bytes
Here is some sample output for this example:
USED_BYTES
———-
363690
SQL> print :alloc_bytes
Here is some sample output for this example:
ALLOC_BYTES
———–
2097152

15
Nov
11

A simple introduction to working with LVM

Posted by Steve on Wed 28 Jun 2006 at 21:22

The logical volume manager allows you to create and manage the storage of your servers in a very useful manner; adding, removing, and resizing partitions on demand. Getting started with LVM can be a little confusing to newcomer so this guide intends to show the basics in a simple manner. There several pieces of terminology that you’ll need to understand to make the best use of LVM. The most important things you must know are: physical volumes. These are your physical disks, or disk partitions, such as /dev/hda or /dev/hdb1. These are what you’d be used to using when mounting/unmounting things.

Using LVM we can combine multiple physical volumes into volume groups. volume groups :A volume group is comprised of real physical volumes, and is the storage used to create logical volumes which you can create/resize/remove and use. You can consider a volume group as a “virtual partition” which is comprised of an arbitary number of physical volumes.

logical volumes These are the volumes that you’ll ultimately end up mounting upon your system. They can be added, removed, and resized on the fly. Since these are contained in the volume groups they can be bigger than any single physical volume you might have. (ie. 4x5Gb drives can be combined into one 20Gb volume group, and you can then create two 10Gb logical volumes.)

Logically these are stacked from top to bottom like this: Dia source file Creating A Volume Group To use LVM you need to take at least one partition, initialise it for use with LVM and then include it in a volume group. Why would you do this? Well it would let you create new partitions on the fly, and make better use of your space. In my case I have a laptop with the following setup:

Name     Flags        PartType      FS Type         [Label]        Size (MB) ——————————————————————————

hda1      Boot           Primary      Linux ext3         [/]                  8000.01

hda2                          Primary      Linux swap      / Solaris          1000.20

hda3                          Primary      Linux                                           31007.57

Here I have a 7Gb root partition which contains my Debian GNU/Linux installation. I also have a 28Gb partition which will be used by LVM. I’ve chosen this setup so that I can create a dedicated /home partition using LVM – and if I need more space I can extend it. In this example hda1, hda2, and hda3 are all physical volumes. We’ll initialize hda3 as a physical volume:

root@lappy:~# pvcreate /dev/hda3

If you wanted to combine several disks, or partitions you could do the same for those:

root@lappy:~# pvcreate /dev/hdb

root@lappy:~# pvcreate /dev/hdc

Once we’ve initialised the partitions, or drives, we will create a volume group which is built up of them:

root@lappy:~# vgcreate skx-vol /dev/hda3

Here “skx-vol” is the name of the volume group. (If you wanted to create a single volume spanning two disks you’d run “vgcreate skx-vol /dev/hdb /dev/hdc”.) If you’ve done this correctly you’ll be able to see it included in the output of vgscan:

root@lappy:~# vgscan Reading all physical volumes. This may take a while… Found volume group “skx-vol” using metadata type lvm2

Now that we have a volume group (called skx-vol) we can actually start using it.

Working with logical volumes :

What we really want to do is create logical volumes which we can mount and actually use. In the future if we run out of space on this volume we can resize it to gain more storage. Depending on the filesystem you’ve chosen you can even do this on the fly! For test purposes we’ll create a small volume with the name ‘test’:

root@lappy:~# lvcreate -n test –size 1g skx-vol

Logical volume “test” created

This command creates a volume of size 1Gb with the name test hosted on the LVM volume group skx-vol. The logical volume will now be accessible via /dev/skx-vol/test, and may be formatted and mounted just like any other partition:

root@lappy:~# mkfs.ext3 /dev/skx-vol/test

root@lappy:~# mkdir /home/test

root@lappy:~# mount /dev/skx-vol/test /home/test

Cool, huh?

Now we get onto the fun stuff. Let us pretend that the test partition is full and we want to make it bigger.

First of all we can look at how big it is at the moment with lvdisplay:

root@lappy:~# lvdisplay — Logical volume — LV Name /dev/skx-vol/test VG Name skx-vol LV UUID J5XlaT-e0Zj-4mHz-wtET-P6MQ-wsDV-Lk2o5A LV Write Access read/write LV Status available # open 0 LV Size 1.00 GB Current LE 256 Segments 1 Allocation inherit Read ahead sectors 0 Block device 254:0

We see it is 1Gb in size (no suprise really!) before we go on to resize the volume remember we should unmount it first:

root@lappy:~# umount /home/test/

root@lappy:~# lvextend -L+1g /dev/skx-vol/test

Extending logical volume test to 2.00 GB

Logical volume test successfully resized

(It is possible to resize ext3 filesystems whilst they’re mounted, but I’d still suggest doing it offline as that is less scary.)

Looking at lvdisplay again we can see the volume was resized:

root@lappy:~# lvdisplay — Logical volume — LV Name /dev/skx-vol/test VG Name skx-vg LV UUID uh7umg-7DqT-G2Ve-nNSX-03rs-KzFA-4fEwPX LV Write Access read/write LV Status available # open 0 LV Size 2.00 GB Current LE 512 Segments 1 Allocation inherit Read ahead sectors 0 Block device 254:0

The important thing to realise is that although the volume has been resized the ext3 filesystem on it has stayed unchanged. We need to resize the filesystem to actually fill the volume:

root@lappy:~# e2fsck -f /dev/skx-vol/test

root@lappy:~# resize2fs /dev/skx-vol/test

Remount the logical volume and you’ll discover it is now only half full instead of completely full! If you get bored of the volume and its contents you can remove it with the lvremove command:

root@lappy:~# lvremove /dev/skx-vol/test

Do you really want to remove active logical volume “test”? [y/n]: y Logical volume “test” successfully removed Other userful commands include lvrename to change the name, and lvreduce to reduce the size of a volume.

Mounting Logical Volumes :

In the previous section we showed how you could mount a logical volume, with a command like this:

mount /dev/skx-vol/test /home/test

If you want your partition to be mounted at boot-time you should update your /etc/fstab to contain an entry like this:

/dev/skx-vol/home /home ext3 noatime 0 2

/dev/skx-vol/backups /backups ext3 noatime 0 2

29
Sep
11

Wait Events – cursor: pin S wait on X cursor:

pin S wait on X A session waits for this event when it is requesting a shared mutex pin and another session is holding an exclusive mutex pin on the same cursor object.

Wait Time:

Microseconds

Parameter Description:

P1 Hash value of cursor

P2 Mutex value (top 2 bytes contains SID holding mutex in exclusive mode, and bottom two bytes usually hold the value 0)

P3 Mutex where (an internal code locator) OR’d with Mutex Sleeps

15
Aug
11

Exporting And Importing SQL Plan Baselines In Oracle 11g

Oracle Database supports the export and import of SQL plan baselines using its import and export utilities or Oracle Data Pump. Use the DBMS_SPM package to define a staging table, which is then used to pack and unpack SQL plan baselines.

To import a set of SQL plan baselines from one system to another:

On the original system, create a staging table using the CREATE_STGTAB_BASELINE procedure:

BEGIN

DBMS_SPM.CREATE_STGTAB_BASELINE(

table_name => ‘stage1’);

END;

/

This example creates a staging table named stage1.

Pack the SQL plan baselines you want to export from the SQL management base into the staging table using the PACK_STGTAB_BASELINE function:

DECLARE

my_plans number;

BEGIN

my_plans := DBMS_SPM.PACK_STGTAB_BASELINE(

table_name => ‘stage1’,

enabled => ‘yes’,

creator => ‘dba1’);

END;

/

This example packs all enabled plan baselines created by user dba1 into the staging table stage1. You can select SQL plan baselines using the plan name (plan_name), SQL handle (sql_handle), or by any other plan criteria. The table_name parameter is mandatory.

  1. Export the staging table stage1 into a flat file using the export command or Oracle Data Pump. –>Exp system/orapw4db  tables=STAGE1 file==stage1_baseline.dmp log=exp_basline.log
  2. Transfer the flat file to the target system.
  3. Import the staging table stage1 from the flat file using the import command or Oracle Data Pump.  –>    imp system/orapw4db fromuser=SYSTEM touser=SYSTEM tables=STAGE1 file=stage1_baseline.dmp log=imp_basline
  4. Unpack the SQL plan baselines from the staging table into the SQL management base on the target system using the UNPACK_STGTAB_BASELINE function:

DECLARE

my_plans number;

BEGIN

my_plans := DBMS_SPM.UNPACK_STGTAB_BASELINE(

table_name => ‘stage1’,

fixed => ‘yes’);

END;

/

Once afer unpack just issue the below query to see the baseline in the database.

SQL> select SQL_HANDLE,SQL_TEXT,ENABLED,ACCEPTED,FIXED FROM dba_sql_plan_baselines;

SQL_HANDLE

——————————

SQL_TEXT

——————————————————————————–

ENA ACC FIX

— — —

SQL_e1ce5b34a129b51e

INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO “RMS”.”ORG14_CUSTPRODUCTPRICES” select

YES YES YES

20
Jul
11

Important Linux Kernel Parameters for Oracle

Configuring Shared Memory

The Oracle database uses shared memory in UNIX to allow processes to access common data structures and data. These data structures and data are placed in a shared memory segment to allow processes the fastest form of Interprocess Communications(IPC) available. The speed is primarily a result of processes not needing to copy data between each other to share common data and structures – relieving the kernel from having to get involved.Oracle uses shared memory in UNIX to hold its Shared Global Area (SGA). This is an area of memory within the Oracle instance that is shared by all Oracle backup and foreground processes. It is important to size the SGA to efficiently hold the database buffer cache, shared pool, redo log buffer as well as other shared Oracle memory structures. Inadequate sizing of the SGA can have a dramatic decrease in performance of the database.

To determine all shared memory limits you can use the ipcs command. The following example shows the values of my shared memory limits on a fresh RedHat Linux install using the defaults:

# ipcs -lm

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 32768
max total shared memory (kbytes) = 8388608
min seg size (bytes) = 1

Let’s continue this section with an overview of the parameters that are responsible for configuring the shared memory settings in Linux.SHMMAX

The SHMMAX parameter is used to define the maximum size (in bytes) for a shared memory segment and should be set large enough for the largest SGA size. If the SHMMAX is set incorrectly (too low), it is possible that the Oracle SGA (which is held in shared segments) may be limited in size. An inadequate SHMMAXsetting would result in the following:

ORA-27123: unable to attach to shared memory segment

You can determine the value of SHMMAX by performing the following:

# cat /proc/sys/kernel/shmmax
33554432

As you can see from the output above, the default value for SHMMAX is 32MB. This is often too small to configure the Oracle SGA. I generally set the SHMMAXparameter to 2GB.

NOTE: With a 32-bit Linux operating system, the default maximum size of the SGA is 1.7GB. This is the reason I will often set the SHMMAX parameter to 2GB since it requires a larger value for SHMMAX.On a 32-bit Linux operating system, without Physical Address Extension (PAE), the physical memory is divided into a 3GB user space and a 1GB kernel space. It is therefore possible to create a 2.7GB SGA, but you will need make several changes at the Linux operating system level by changing the mapped base. In the case of a 2.7GB SGA, you would want to set the SHMMAX parameter to 3GB.

Keep in mind that the maximum value of the SHMMAX parameter is 4GB.

To change the value SHMMAX, you can use either of the following three methods:

  • This is method I use most often. This method sets the SHMMAX on startup by inserting the following kernel parameter in the /etc/sysctl.confstartup file:
    # echo "kernel.shmmax=2147483648" >> /etc/sysctl.conf

    If you wanted to dynamically alter the value of SHMMAX without rebooting the machine, you can make this change directly to the /proc file system. This command can be made permanent by putting it into the /etc/rc.localstartup file:

  • # echo "2147483648" > /proc/sys/kernel/shmmax

    You can also use the sysctl command to change the value of SHMMAX:

  • # sysctl -w kernel.shmmax=2147483648

SHMMNI

We now look at the SHMMNI parameters. This kernel parameter is used to set the maximum number of shared memory segments system wide. The default value for this parameter is 4096. This value is sufficient and typically does not need to be changed.

You can determine the value of SHMMNI by performing the following:

# cat /proc/sys/kernel/shmmni
4096

SHMALL

Finally, we look at the SHMALLshared memory kernel parameter. This parameter controls the total amount of shared memory (in pages) that can be used at one time on the system. In short, the value of this parameter should always be at least:

ceil(SHMMAX/PAGE_SIZE)

The default size of SHMALLis 2097152 and can be queried using the following command:

# cat /proc/sys/kernel/shmall
2097152

From the above output, the total amount of shared memory (in bytes) that can be used at one time on the system is:

SM = (SHMALL * PAGE_SIZE)
   = 2097152 * 4096
   = 8,589,934,592 bytes

The default setting for SHMALL should be adequate for our Oracle installation.

NOTE: The page size in Red Hat Linux on the i386 platform is 4096 bytes. You can, however, use bigpages which supports the configuration of larger memory page sizes.

Configuring Semaphores

Now that we have configured our shared memory settings, it is time to take care of configuring our semaphores. A semaphore can be thought of as a counter that is used to control access to a shared resource. Semaphores provide low level synchronization between processes (or threads within a process) so that only one process (or thread)has access to the shared segment, thereby ensureing the integrity of that shared resource. When an application requests semaphores, it does so using “sets”.To determine all semaphore limits, use the following:

# ipcs -ls

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

You can also use the following command:

# cat /proc/sys/kernel/sem
250     32000   32      128

SEMMSL

The SEMMSLkernel parameter is used to control the maximum number of semaphores per semaphore set.

Oracle recommends setting SEMMSL to the largest PROCESS instance parameter setting in the init.ora file for all databases hosted on the Linux system plus 10. Also, Oracle recommends setting the SEMMSL to a value of no less than 100.

SEMMNI

The SEMMNIkernel parameter is used to control the maximum number of semaphore sets on the entire Linux system.

Oracle recommends setting the SEMMNI to a value of no less than 100.

SEMMNS

The SEMMNSkernel parameter is used to control the maximum number of semaphores (not semaphore sets) on the entire Linux system.

Oracle recommends setting the SEMMNS to the sum of the PROCESSES instance parameter setting for each database on the system, adding the largest PROCESSES twice, and then finally adding 10 for each Oracle database on the system. To summarize:

SEMMNS =   sum of PROCESSES setting for each database on the system
         + ( 2 * [largest PROCESSES setting])
         + (10 * [number of databases on system]

To determine the maximum number of semaphores that can be allocated on a Linux system, use the following calculation. It will be the lesser of:

SEMMNS  -or-  (SEMMSL * SEMMNI)

SEMOPM

The SEMOPM kernel parameter is used to control the number of semaphore operations that can be performed per semopsystem call.

The semop system call (function) provides the ability to do operations for multiple semaphores with one semop system call. A semaphore set can have the maximum number of SEMMSL semaphores per semaphore set and is therefore recommended to set SEMOPM equal to SEMMSL.

Oracle recommends setting the SEMOPM to a value of no less than 100.

Setting Semaphore Kernel Parameters

Finally, we see how to set all semaphore parameters using several methods. In the following, the only parameter I care about changing (raising) is SEMOPM. All other default settings should be sufficient for our example installation.

  • This is method I use most often. This method sets all semaphore kernel parameters on startup by inserting the following kernel parameter in the /etc/sysctl.confstartup file:
    # echo "kernel.sem=250 32000 100 128" >> /etc/sysctl.conf

    If you wanted to dynamically alter the value of all semaphore kernel parameters without rebooting the machine, you can make this change directly to the /proc file system. This command can be made permanent by putting it into the /etc/rc.localstartup file:

  • # echo "250 32000 100 128" > /proc/sys/kernel/sem

    You can also use the sysctlcommand to change the value of all semaphore settings:

  • # sysctl -w kernel.sem="250 32000 100 128"
29
Jun
11

Script to find sizes of SGA

COLUMN sum_bytes new_value divide_by noprint
COLUMN percent format 999.99999
SET pages 60 lines 80 feedback off verify off
BREAK on report
COMPUTE sum of bytes on report
COMPUTE sum of percent on report
SELECT SUM (VALUE) sum_bytes
  FROM SYS.v_$sga;
TTITLE left _date center 'SGA Component Sizes Report' skip 2
WITH total_size AS
     (SELECT SUM (VALUE) sum_bytes
        FROM SYS.v_$sga)
SELECT   a.NAME, a.BYTES, a.BYTES / b.sum_bytes * 100 PERCENT
    FROM SYS.v_$sgastat a, total_size b
ORDER BY BYTES DESC
/
CLEAR columns
CLEAR breaks
SET pages 22 lines 80 feedback on verify on
TTITLE off
27
May
11

Manually create Orainventory in case its corrupted

(1) Oracle Database Server is already installed and you want to add it to a inventory or create a new one for it
——————————————————————————————————————
a) Set the ORACLE_HOME variable to the path of the installable to be registered
export ORACLE_HOME=/oratpapcd1p01/u01/app/oracle/product/11.2.0/TPAPCD1P

b) Edit the entries in the $ORACLE_HOME/oraInst.loc file to point to the inventory location whcih in our case usually follows the below convention

inventory_loc=/oratpapcd1p01/u01/app/oracle/oraInventory
inst_group=dba

c) Then follow the below steps to register the new oracle home

cd $ORACLE_HOME/oui/bin
./runInstaller -silent -invPtrLoc $ORACLE_HOME/oraInst.loc -attachHome ORACLE_HOME=”/oratpapcd1p01/u01/app/oracle/product/11.2.0/TPAPCD1P” ORACLE_HOME_NAME=”Ora11gR2Home”

d) You can verify that the inventory is updated/created by running

$ORACLE_HOME/OPatch/opatch lsinventory -invPtrLoc $ORACLE_HOME/oraInst.loc

(2) You want to specify the orainventory location during the installation of Oracle Database Server then run the runInstaller command as such
——————————————————————————————————————

./runInstaller -invPtrLoc $ORACLE_HOME/oraInst.loc

29
Apr
11

Reasons and Tips

Library cache pin: Waits on library cache pin will often be caused by a session trying to modify or compile a PL/SQL program that is simultaneously being executed by another session.

Cache buffer chains latch: To reduce cache buffer chain latch contention,try reducing logical reads against the hot object by changing indexing options, partitioning  the object concerned, or by tuning SQL against the object.

21
Mar
11

How to Restoring Stats in Oracle 10g

Using RESTORE_TABLE_STATS

SQL> select TABLE_NAME, STATS_UPDATE_TIME from dba_tab_stats_history where table_name = ‘PICKED_SHIPMENT_BATCHES’;

TABLE_NAME                     STATS_UPDATE_TIME

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

PICKED_SHIPMENT_BATCHES        30-OCT-10 07.50.59.539450 PM +02:00

How does Oracle maintain the Statistics History?

We can check the oldest statistics that can be restore using GET_STATS_HISTORY_AVAILABILITY procedure.

SQL> select DBMS_STATS.GET_STATS_HISTORY_AVAILABILITY  from dual;

GET_STATS_HISTORY_AVAILABILITY

—————————————————————————

30-SEP-10 11.22.25.817428000 PM +01:00

Usually Oracle retains stats for 1 month (31 days).

DCFRA1>select DBMS_STATS.GET_STATS_HISTORY_RETENTION from dual;

GET_STATS_HISTORY_RETENTION

—————————

31

You can change the retention using ALTER_STATS_HISTORY_RETENTION procedure

 

PICKED_SHIPMENT_BATCHES        31-OCT-10 12.02.58.979300 AM +02:00

PICKED_SHIPMENT_BATCHES        31-OCT-10 12.17.19.315201 AM +02:00

STATS_UPDATE_TIME tells us when the stats were last updated.

Step 2) Check when was the table last analyzed

DCFRA1>select last_analyzed from dba_tables where table_name = ‘PICKED_SHIPMENT_BATCHES’;

LAST_ANALYZED

—————-

2010-10-31:20:12

Step 3) Use DBMS_STATS.RESTORE_TABLE_STATS procedure to restore the stats on the table

SQL> execute dbms_stats.restore_table_stats(<OWNER>,<TABLE_NAME>,<TIMESTAMP WITH TIMEZONE>);

Timestamp could be any timestamp in STATS_UPDATE_TIME column of dba_tab_stats_history table.

After restore, Check the last_analyzed date from dba_table and you should see the old date.
Following is a short FAQ on statistics.

Where does oracle store the statistics?

Oracle DBA_OPTSTAT_OPERATIONS table contains a log history of statistics collected.

SQL> select OPERATION, START_TIME, END_TIME from dba_optstat_operations;

OPERATION                      START_TIME                               END_TIME

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

gather_database_stats(auto)    30-OCT-10 06.00.04.042555 AM +02:00      31-OCT-10 11.00.02.114381 PM +01:00

 

 


02
Feb
11

How to improve Import/ Export performance?

EXPORT:

  • Set the BUFFER parameter to a high value (e.g. 2Mb — entered as an integer “2000000”)
  • Set the RECORDLENGTH parameter to a high value (e.g. 64Kb — entered as an integer “64000”)
  • Use DIRECT=yes (direct mode export)
  • Stop unnecessary applications to free-up resources for your job.
  • If you run multiple export sessions, ensure they write to different physical disks.
  • DO NOT export to an NFS mounted filesystem. It will take forever.

IMPORT:

  • Create an indexfile so that you can create indexes AFTER you have imported data. Do this by setting INDEXFILE to a filename and then import. No data will be imported but a file containing index definitions will be created. You must edit this file afterwards and supply the passwords for the schemas on all CONNECT statements.
  • Place the file to be imported on a separate physical disk from the oracle data files
  • Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) considerably in the init$SID.ora file
  • Set the LOG_BUFFER to a big value and restart oracle.
  • Stop redo log archiving if it is running (ALTER DATABASE NOARCHIVELOG;)
  • Create a BIG tablespace with a BIG rollback segment inside. Set all other rollback segments offline (except the SYSTEM rollback segment of course). The rollback segment must be as big as your biggest table (I think?)
  • Use COMMIT=N in the import parameter file if you can afford it
  • Use STATISTICS=NONE in the import parameter file to avoid time consuming to import the statistics
  • Remember to run the indexfile previously created



Its Mee :)

Unknown's avatar
Welcome to My Blog:
In this Blog you will find the Oracle stuff which i came across and experienced as DBA. So would like to share with you all so that everyone gets benefited.

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Blog Stats

  • 97,697 hits

Create your own website, free on WordPress.com.Create your own website.
Start free