Friday, November 28, 2014

Oracle Performance Tuning

SQL_ID and CPU Usage
SQL> select * from (
             select sql_id, inst_id,
                sum(decode(vash.session_state, 'ON CPU', 1,0)) as "Number on CPU",
                sum(decode(vash.session_state, 'WAITING', 1, 0)) as "Number Waiting on CPU"
             from gv$active_session_history cash
             where sample_time > sys date -5/(60*24)
             group by sql_id, instead
             order by 3 desc
             ) where rownum <11;

Query top 10 SQL_ID's in the last 10 minutes

select * from
(select NVL(SQL_ID,'NULL') AS SQL_ID,
SUM(1) AS "DBTime IN SECONDES" FROM V$ACTIVE_SESSION_HISTORY
WHERE sample_time > sys date - 10/(24*60)
GROUP BY SQL_ID
ORDER BY 2 DESC)
WHERE ROWNUM < 11;

Wait Events Across Nodes
select * from (
select sql_id, inst_id,
                sum(decode(vash.session_state, 'ON CPU', 1,0)) as "Number on CPU",
                sum(decode(vash.session_state, 'WAITING', 1, 0)) as "Number Waiting on CPU",
                event , count(distinct(session_id||session_serial#)) as "SESSION COUNT"
             from gv$active_session_history cash
             where sample_time > sys date -5/(60*24)
             group by event,sql_id, instead
             order by 3 desc
             ) where rownum <11;

IO Waits by object from ASH

SELECT TW.*, DO.object_name from (
select current_obj#,
ROUND(SUM(CASE WHEN TIME_WAITED >= 1000000 THEN 1
ELSE 1000000 / TIME_WAITED END)) AS "Estimated IO Waits",
SUM(1) AS "ESTIMATED DBTIME"
FROM V$ACTIVE_SESSION_HISTORY
WHERE sample_time > sysdate - 5/(24*60) and TIME_WAITED > 0
and WAIT_CLASS = 'User I/O'
GROUP BY CURRENT_OBJ#
ORDER BY 2 DESC) TW, DBA_OBJECTS DO
WHERE DO.object_id=TW.current_obj#
and ROWNUM < 11;

Thursday, November 27, 2014

Oracle: Preliminary Connection

Login as oracle
$ sqlplus -prelim "/as sysdba"

 SQL> shutdown abort
 ORACLE instance shut down.
 SQL> exit


$ sqlplus / as sysdba
SQL> startup

Tuesday, November 25, 2014

Oracle VM Manager/VM Server: Migrate virtual machine between in-compatible/in different pool


  1. Shutdown target virutla machine
  2. Create same size virtual disk on target server
  3. Copy the existing virtual disk to replace the file generated in last step
  4. Create network for the target virtual machine
  5. Create new virtual machine with same configuration as original virutal machine
  6. Start up target virtual machine
To Create another Oracle VM Manager to replace existing one:

      Copy the UUID of your original Oracle VM Manager from the file /u01/app/oracle/ovm-manager-3/.config.

    After mounting the Oracle VM Manager install dvd on the file system of your virtual machine, run the installer as follows: ./runinstaller.sh --uuid <original_manager_uuid>. Select your preferred installation type, as you would with a regular install.

Stop your original Oracle VM Manager.
From the new Oracle VM Manager virtual machine, rediscover your Oracle VM Server and storage, and refresh your storage repository to make sure that that all your VM resources reappear.
After rediscovering the minimal setup, proceed with the installation and configuration of your full Oracle VM environment.

Tuesday, November 18, 2014

Oracle: Check Table Analyzed Time


SELECT t.owner,

       t.table_name AS "Table Name",

       t.num_rows AS "Rows",

       t.avg_row_len AS "Avg Row Len",

       Trunc((t.blocks * p.value)/1024) AS SizeKB,

       to_char(t.last_analyzed,'DD/MM/YYYY HH24:MM:SS') AS "Last Analyzed"

FROM   dba_tables t,

       v$parameter p

WHERE t.owner like '%PROD'

AND   p.name = 'db_block_size'

ORDER by t.table_name,t.owner,t.last_analyzed desc,t.table_name

/

Friday, November 14, 2014

Tinycore Resources

Install SSH on Tinycore Linux

$ sudo tce-load -iw openssh.tcz
$ sudo cp /usr/local/etc/ssh/sshd_config.example /usr/local/etc/ssh/sshd_config
$ sudo /usr/local/etc/init.d/openssh start
Persist sshd
Append below lines to /opt/.filetool.lst


http://gr8idea.info/os/tutorials/tiny-core/resolution.html
/usr/local/etc/ssh
/etc/passwd
/etc/shadow

Protect user tc with password

Automatically start up sshd
Append below line to /opt/bootlocal.sh
/usr/local/etc/init.d/openssh start

Backup new configurations
$sudo filetool.sh -b

Change Display Resolution

To change the screen resolution, in the menu (right mouse click), go to Tools -> Xvesa Setup. You will see a new window where you can change the screen resolution. Set this as desired, and press "Enter." You will see a new window where you can select the mouse type. Select the appropriate type, and press "Enter." For this to take effect, you need to turn the computer off and restart. To save settings, you must Backup when shutting down Tiny Core.

$ sudo filetool.sh -b

Alternate Methods

Another way to change the screen resolution is to edit the Grub menu. Open the file "menu.lst" in Grub, and add "xsetup" to the end of the line which begins with "kernel   /boot/bzImage." After starting the computer, you will be able to select the screen resolution and mouse type. To save these settings, you must Backup when shutting down Tiny Core. Once this is set up, you can remove "xsetup" from Grub.
If using the live CD, when you get to the boot prompt, type "tinycore xsetup" and press enter.

Xorg

If Xorg is installed, Xvesa Setup won't run. To overcome this, remove Xorg from the tce directory, start the computer without it, run Xvesa Setup, then put Xorg back. Restart the computer for it to be loaded.

Friday, November 7, 2014

Oracle DB Optimization


Some info on the Optimizer, Optimizer Mode and the Cost Based Approach:  http://docs.oracle.com/cd/B28359_01/server.111/b28274/optimops.htm#PFGRF001

http://www.dba-oracle.com/art_otn_cbo.htm


SET LINESIZE 300


SELECT t.owner,

       t.table_name AS "Table Name",

       t.num_rows AS "Rows",

       t.avg_row_len AS "Avg Row Len",

       Trunc((t.blocks * p.value)/1024) AS "Size KB",

       to_char(t.last_analyzed,'DD/MM/YYYY HH24:MM:SS') AS "Last Analyzed"

FROM   dba_tables t,

       v$parameter p

WHERE t.owner like '%PROD'

AND   p.name = 'db_block_size'

ORDER by t.owner,t.last_analyzed desc,t.table_name

/