PoJokAndZs

Automate kill inactive user in oracle database

June 10, 2009 · Leave a Comment

Step by step to automatically kill inactive user in oracle database
To see inactive user in oracle database you can use this query “select * from v$session where status=’INACTIVE’ or user=’sys’”
1. Create procedure for killing inactive oracle database user (oracle user have to be grant dbms_sql to execute this procedure)
CREATE OR REPLACE PROCEDURE kill_session_1 ( session_id in varchar2,serial_num in varchar2)
AS
cur INTEGER;
ret INTEGER;
string VARCHAR2(100);
BEGIN

– Comment out the following three lines to
– not use KILL

string :=’ALTER SYSTEM KILL SESSION’ || CHR(10) ||CHR(39)||session_id||’,'||serial_num||CHR(39);

– Uncomment the following 4 lines to use DISCONNECT

–string := ‘ALTER SYSTEM DISCONNECT SESSION’ || CHR(10) || CHR(39)||session_id||’,'||serial_num||CHR(39)||CHR(10)||’ POST_TRANSACTION’;
cur := dbms_sql.open_cursor;
dbms_sql.parse(cur,string,dbms_sql.native);
ret := dbms_sql.execute(cur) ;
dbms_sql.close_cursor(cur);
END;
/
2. Create sql script ORA_KILL.sql for spooling command to execute procedure created (see no 1)
REM
REM ORA_KILL.SQL
REM FUNCTION: Kills nonessential Oracle sessions (those that aren’t
REM owned)
REM : by SYS or “NULL”
REM DEPENDENCIES: Depends on kill_session procedure
REM MRA 9/12/96
REM
SET HEADING OFF TERMOUT OFF VERIFY OFF ECHO OFF
SPOOL kill_all.sql
SELECT ‘EXECUTE kill_session_1(‘||chr(39)||sid||chr(39)||’,'||
chr(39)||serial#||chr(39)||’);’ FROM v$session
WHERE username = ‘ECARE2′ and status=’INACTIVE’
/
SPOOL OFF
START kill_all.sql

3. Create shell script to automate execute sql script using cronjob (for unix user)
sqlplus -s $schema/$pass@$dbLink as sysdba<<!
set timing on
@ORA_KILL

→ Leave a CommentCategories: Uncategorized

RMAN setup using catalog database quick guide

June 10, 2009 · Leave a Comment

To setup RMAN using catalog database follow these steps :
1. Create user for catalog database repository in catalogue database
-Create tablespace for catalog database
sql>CREATE TABLESPACE RMAN_CAT
DATAFILE ‘RMAN_CAT’ SIZE 500 M
-Create user for catalog database
sql>create user rman_cat identified by rman_cat
temporary tablespace temp
default tablespace rman_cat
quota unlimited on rman_cat
-Grant appropriate privilege for user created
sql>grant recovery_catalog_owner,resource,create session to rman_cat
-Connect to recovery catalog using RMAN
$rman catalog rman_cat/rman_cat@rman_cat
RMAN>create catalog tablespace rman_cat
2. Connect to target database (Database to be backup) and catalog database using RMAN
-Connect using rman and register database
$rman target sys/pass@target catalog rman_cat/rman_cat@rman_cat
RMAN>register database;
-Check RMAN configuration
RMAN> Show all;
Command above will see RMAN configuration

→ Leave a CommentCategories: Uncategorized

SQL query for monitoring (next article Oracle Database Monitoring For Beginner)

April 18, 2009 · Leave a Comment

This article is the sequel of my article Oracle Database Monitoring for Beginner

1. Query for Status Monitoring
Examples of Status Monitoring are, check tablespace where it’s about to fills up, check segment near their maximum extents.
-Tablespace related
This query will show tablespace with percentage free less than 20 percent or equal 20 percent
select ddf.TABLESPACE_NAME,
ddf.BYTES,
ddf.BYTES-DFS.BYTES “BYTES_USED”,
round(((ddf.BYTES-dfs.BYTES)/ddf.BYTES)*100,2) “PERCENT_USED”,
dfs.BYTES “BYTES_FREE”,
round((1-((ddf.BYTES-dfs.BYTES)/ddf.BYTES))*100,2) “PERCENT_FREE”
from (select TABLESPACE_NAME,
sum(BYTES) bytes
from   dba_data_files
where autoextensible=’NO’
group  by TABLESPACE_NAME) ddf,
(select TABLESPACE_NAME,
sum(BYTES) bytes
from dba_free_space
group by TABLESPACE_NAME) dfs
where ddf.TABLESPACE_NAME=dfs.TABLESPACE_NAME and round((1-((ddf.BYTES-dfs.BYTES)/ddf.BYTES))*100,2) < 20 or              round((1-((ddf.BYTES-dfs.BYTES)/ddf.BYTES))*100,2) = 20
order by ((ddf.BYTES-dfs.BYTES)/ddf.BYTES) desc

Query to show tablespace and the datafile
SELECT dfs.TABLESPACE_NAME, SUBSTR (df.NAME, 1, 70) file_name, df.bytes / 1024 / 1024 allocated_mb,
((df.bytes / 1024 / 1024) – NVL (SUM (dfs.bytes) / 1024 / 1024, 0))
used_mb,
NVL (SUM (dfs.bytes) / 1024 / 1024, 0) free_space_mb
FROM v$datafile df, dba_free_space dfs
WHERE df.file# = dfs.file_id(+)
GROUP BY dfs.file_id, df.NAME, df.file#, df.bytes, dfs.TABLESPACE_NAME
ORDER BY file_name

-Oracle Objects Extents related
Show objects more than 50% of Max Extents
select   OWNER,
TABLESPACE_NAME,
SEGMENT_NAME,
SEGMENT_TYPE,
BYTES,
EXTENTS,
MAX_EXTENTS,
(EXTENTS/MAX_EXTENTS)*100 \”PERCENTAGE\”
from     dba_segments
where    SEGMENT_TYPE in (‘TABLE’,'INDEX’)
and      EXTENTS > MAX_EXTENTS/2
order by (EXTENTS/MAX_EXTENTS) desc

Show Segment near their maximum extents
SELECT e.owner,
e.segment_type,
Substr(e.segment_name, 1, 30) “SEGMENT_NAME”,
Trunc(s.initial_extent/1024) “INITIAL K”,
Trunc(s.next_extent/1024) “NEXT K”,
s.max_extents,
Count(*) as extents
FROM   dba_extents e,
dba_segments s
WHERE  e.owner        = s.owner
AND    e.segment_name = s.segment_name
AND    e.owner        NOT IN (‘SYS’, ‘SYSTEM’)
GROUP BY e.owner, e.segment_type, e.segment_name, s.initial_extent, s.next_extent, s.max_extents
HAVING Count(*) > s.max_extents – 10
ORDER BY e.segment_type, e.owner, e.segment_type, Count(*) DESC

-Show Oracle session related and memory used
SELECT NVL(a.username,’(oracle)’) AS username,
a.sid,
a.serial#,
a.machine,
a.module,
a.program,
a.LOGON_TIME,
a.status,
a.process,
Trunc(b.value/1024) AS memory_kb
FROM   v$session a,
v$sesstat b,
v$statname c
WHERE  a.sid = b.sid
AND    b.statistic# = c.statistic#
AND    c.name = ’session pga memory’
AND    a.program IS NOT NULL
ORDER BY  MEMORY_KB desc, a.MODULE asc,username desc

2. Query for Performance Monitoring
-Show Oracle Hit Ratio
Dictionary Hit Ratio
The ratio of cache hits to cache lookup attempts in the data dictionary cache. In other words, the rate the database goes to the dictionary   instead of the hard disk to retrieve data. A low ratio suggests more RAM should be added
The Dictionary Hit Ratio value have to be more than 90 percent
SELECT sum(gets) “GETS”,sum(getmisses) “CACHE MISSES”,round((1 – (sum(getmisses) / sum(gets))) * 100,3) “DICTIONARY”
FROM v$rowcache

Buffer Hit Ratio
The rate the database goes to the buffer instead of the hard disk to retrieve data. A low ratio suggests more RAM should be added to the system.
Buffer hit ratio have to be more than 85%
SELECT cur.value “block”,con.value “con”,phy.value “phy”, ROUND((1-(phy.value / (cur.value + con.value)))*100,2) “BUFFER”
FROM v$sysstat@”.$dbName.” cur, v$sysstat@”.$dbName.” con, v$sysstat@”.$dbName.” phy
WHERE cur.name = ‘db block gets’
AND con.name = ‘consistent gets’
AND phy.name = ‘physical reads’

Library Hit Ratio
Monitors the percentage of entries in the library cache that were parsed more than once (reloads) over the lifetime of the instance.
Library Hit Ratio have to be more than 95%
SELECT sum(pins) “EXEC”, sum(pinhits) “EXEC HITS”, round((sum(pinhits) / sum(pins)) * 100,3) “HIT RATIO”, sum(reloads) “MISSES”,round((sum(pins) / (sum(pins) + sum(reloads))) * 100,3) “HITRATIO”
FROM v$librarycache

-Show memory usage by user connected
SELECT NVL(a.username,’(oracle)’) AS username,
a.machine,
a.module,
a.program,
Trunc(b.value/1024) AS memory_kb
FROM   v$session a,
v$sesstat b,
v$statname c
WHERE  a.sid = b.sid
AND    b.statistic# = c.statistic#
AND    c.name = ’session pga memory’
AND    a.program IS NOT NULL
ORDER BY  MEMORY_KB desc, a.MODULE asc,username desc

-Show Oracle Sort Information
select name,to_char(value,’999,999,999,999,999′) “VALUE”
from sys.v_$sysstat
where name like ’sort%’
Show hit ratio for sort
Sorting percentage on disk have less than 5 %. If the value more than 5 % then change parameter SORT_AREA_SIZE.
select to_char(100*a.value/decode((a.value+b.value),0,1,(A.value+b.value)),’999.90′) “VALUE”
from sys.v_$sysstat a, sys.v_$sysstat b
where a.name = ’sorts (disk)’
and b.name = ’sorts (memory)’

-Show Oracle SGA Info
select name, to_char(value,’999,999,999,999,999′) “VALUE” from sys.v_$sga

-Show Oracle Invalid Objects
This query is to show invalid objects in Oracle
select OWNER,
OBJECT_TYPE,
OBJECT_NAME,
STATUS
from dba_objects
where STATUS = ‘INVALID’
order by OWNER, OBJECT_TYPE, OBJECT_NAME

Solution :
if the object invalid you can recompile it or you can delete it if it’s not used.
sql : SQL>ALTER PROCEDURE PROC_NAME COMPILE ;
SQL>ALTER PACKAGE PACKAGE_NAME COMPILE ;
SQL>ALTER VIEW VIEW_NAME COMPILE ;
Or if you have many invalid objects run this script reside in :  $ORACLE_HOME/rdbms/admin/utlrp.sql
Login to sqlplus
sqlplus > @utlrp

-Show Query running in Oracle
This query will show currently queries running in Oracle.
SELECT *
FROM (SELECT Substr(a.sql_text,1,50) sql_text,Trunc(a.disk_reads/Decode(a.executions,0,1,a.executions))     reads_per_execution,a.buffer_gets,a.disk_reads,a.executions,a.sorts,a.address FROM v$sqlarea a) WHERE  rownum <= 10

To be continued ……………………………

→ Leave a CommentCategories: IT TipZzz · Oracle
Tagged: , , , , ,

Drop tablespace with missing datafile

January 27, 2009 · 2 Comments

Today i have my new server installed with oracle 10G and i have to migrate old oracle 8i to this newly machine. I’ve already succeed mograting from oracle8i to oracle 10G by using export / import utility in oracle (later i will post how to do it in this blog)

Unfortunately i’m accidentally delete one datafile (not the system datafile) and when i want to shutdown the database i get this error code 

ORA-01157: cannot identify/lock data file 121 – see DBWR trace file

ORA-01110: data file 121: ‘/ora_data/ORADATA/USAGE_INDEX23_01.dbf’

to solve just do this simple step:

1.Shutdown abort your database to force shutdown

    sqlplus > shutdown abort

2.Startup mount database

 sqlplus > startup mount

3.After that issue this following command

sqlplus > ALTER DATABASE DATAFILE ‘<datafile name with complete path>’ OFFLINE DROP;

4.Then open the database

sqlplus > alter database open

5.Drop the tablespace by issue this following command

DROP TABLESPACE <tablespace name> INCLUDING CONTENTS;

6.After that if you have backup your database you can recover your tablespace.

→ 2 CommentsCategories: Oracle
Tagged: , ,

WE WILL NOT GO DOWN (Song for Gaza)

January 16, 2009 · 1 Comment

SONG DEDICATED TO PALESTINIAN

WE WILL NOT GO DOWN (Song for Gaza)

(Composed by Michael Heart)

Copyright 2009

A blinding flash of white light

Lit up the sky over Gaza tonight

People running for cover

Not knowing whether they’re dead or alive

They came with their tanks and their planes

With ravaging fiery flames

And nothing remains

Just a voice rising up in the smoky haze

We will not go down

In the night, without a fight

You can burn up our mosques and our homes and our schools

But our spirit will never die

We will not go down

In Gaza tonight Women and children alike

Murdered and massacred night after night

While the so-called leaders of countries afar

Debated on who’s wrong or right

But their powerless words were in vain

And the bombs fell down like acid rain

But through the tears and the blood and the pain

You can still hear that voice through the smoky haze

We will not go down

In the night, without a fight

You can burn up our mosques and our homes and our schools

But our spirit will never die

We will not go down

In Gaza tonight

→ 1 CommentCategories: Uncategorized
Tagged: , , ,

Happy New Year 1430 Hijriah and 2009

January 6, 2009 · Leave a Comment

Happy new year 1430 Hijriah and 2009…..

Hope we all will be better people in this very new year….. Amin….

Alhamdulillah for the things we got in 1429 Hijriah and 2008, bad things and good things is not coming for no reasons, but it gives us experiences, to strengthen us, to taught us to be the best person,  give our best for everything goods  and do not ever we lost tracks ( Follow Alquran and the prophet Muhammad ways)

And to my fellow Muslim Palestinian ..I am praying for you… Your victory will come…

→ Leave a CommentCategories: Uncategorized

Oracle Database Monitoring For Beginner (The Simple Way)

August 27, 2008 · 1 Comment

  • Why Monitor Oracle Database
  • Database need to be monitored to check the performance of the monitored database, so we can change the database parameter based on result from monitoring and keep the database in it’s best performance.

    Database monitoring also needed so we always know the condition of database, and know the symptom of our database and we can take action right before more problem happens to database.

  • Types of Oracle Database Monitoring
  • Database Monitoring can be grouped into three types :

  • 1. Status monitoring
  • This monitoring type monitors current status of an events and give reports or alert when it exceeds a defined threshold

    Examples of Status Monitoring are, check tablespace where it’s about to fills up, check segment near their maximum extents.

  • 2. Performance monitoring
  • Monitors oracle instance memory (sga, buffer, etc), sql query running in database, session which consumes a lot of memory, etc.

    Examples of Performance monitoring are, query from v_$sqlarea to check what SQL has been running in our Oracle Machine, query from v$sgastat and query to get hit ratio for cache , library and buffer cache.

  • 3. Trend Analysis
  • Collects historical data on specific event that occur in database like SGA status, segment that cannot extends, filled up tablespace and make analysis from that historical data so that we can predict the status of SGA in any given time or we can now when the tablespace will filled up.

    Examples of Trend Analysis are, make a histroy table for events we monitored. We can make history table for tablespace so that from that history table we could gain information and make prediction when will the time the tablespace will be filled up. Or we can make history table from v_$session, so from that table we can know what time our database accessed by so many user.

    Next is the query to monitored database … soon…

    There are two ways to write error-free programs. Only the third one works.

     

     

→ 1 CommentCategories: IT TipZzz · Uncategorized

Movie Quotes From When Harry Met Sally

July 7, 2008 · Leave a Comment

→ Leave a CommentCategories: AndZs Story
Tagged: ,

T-Sel Bundling dengan iPhone 3G

July 5, 2008 · 1 Comment

Tanggal 26 Juni 2008 dapet email dari milis pegawai di kantor yang isinya tentang T-Sel dan iPhone. Berita selengkapnya bisa dilihat dibawah. Yang pasti dengan membeli iPhone 3G kita udah dapet fitur seperti iPod Touch n bisa bwat telpon. Sayangnya sih dari gambar2 yg iPhone 3G yg pernah gw liat dia gak ada kamera depan (yach gak bisa video call pake kamera depan donk, masih tetep menang 6120 C gw :D )

Telkomsel Siap tawarkan iPhone Murah

Written by halim

Wednesday, 28 May 2008

Jakarta – Telkomsel berniat mengikuti jejak Singtel yang akan membundling ponsel iPhone keluaran Apple. Telkomsel pun ingin menawarkannya dengan harga yang lebih murah dari pasaran.

Namun sayangnya, menurut Vice President Corporate Account PT Telkomsel, Ivan Ho, program bundling tersebut baru akan ditawarkan pada pelanggan pascabayar korporat.

“Detail kapannya belum bisa kami pastikan berhubung iPhone juga belum masuk ke Indonesia. Tapi kami ada niatan untuk menawarkan dengan harga yang lebih murah,” ujarnya kepada detikINET, di sela seminar dan ekshibisi layanan korporat Telkomsel di Hotel Gran Melia, Jakarta, Selasa (13/5/2008).

Mungkinkah Telkomsel iPhone di Indonesia?

Written by halim

Tuesday, 24 June 2008

JAKARTA – Rumor mengenai Telkomsel yang mendapatkan mandat memasok iPhone bisa jadi benar adanya. Pasalnya, Telkomsel merupakan operator yang disinyalir memiliki kriteria yang cukup kuat untuk bisa membujuk Apple menyerahkan sebagian iPhone 3G-nya untuk dibundle dengan operator dominan di negeri ini.

Saat ini Telkomsel dan SingTel sama-sama termasuk operator terbesar di negaranya masing-masing, Indonesia dan Singapura. Bahkan beberapa operator lainnya pun memiliki posisi yang sama, setidaknya berada di posisi pertama dan kedua terbesar di negara masing-masing.

Image

Belum lagi, hubungan yang cukup erat antara SingTel dengan Telkomsel melalui suntikan saham. Seperti diketahui, SingTel saat ini memiliki kontribusi saham sebesar 35 persen di tubuh Telkomsel sedangkan sisanya sebesar 65 persen masih dikuasai Telkom.

Bahkan beberapa operator yang mendapatkan jatah pasokan iPhone ditengarai juga memiliki hubungan sangat dekat dengan Sing Tel. Sebut saja Bharti Airtel, Globe Telecom dan Optus. Masing-masing operator tersebut ditugaskan untuk menggelontorkan gadget multimedia milik Apple itu ke negara masing-masing.

Bharti akan memasok iPhone ke India, Globe Telecom mendapat jatah pasar di Filipina sedangkan Optus mendapat kewajiban untuk memasarkan iPhone ke Australia.

Dikutip melalui situs resmi SingTel, Senin (23/6/2008), pada tahun 2001, perusahaan telekomunikasi terbesar di Asia itu telah berhasil mengakuisisi Optus, yang kala itu menduduki posisi operator nomor dua terbesar di Australia. Bahkan beberapa perusahaan besar lainnya di Asia juga disusupi oleh SingTel. Di Bharti, SingTel punya sekira 30,5 persen saham dengan jumlah pelanggan di India saat ini mencapai 64 juta. Sedangkan di Globe, SingTel menyusup dengan 44,5 persen saham dan telah meraih 21,3 juta pelanggan di Filipina. Di Singapura dan Australia sendiri, SingTel dan Optus masing-masing memiliki 2,3 juta dan 7 juta pelanggan.

Dengan hubungan yang erat tersebut, dan tentunya jumlah pelanggan paling besar yang dimiliki Telkomsel hingga mencapai lebih dari 50 juta pelanggan, bukan tidak mungkin jika Telkomsel pun akan kebagian jatah untuk memberikan pengalaman multimedia yang mengesankan dengan menggunakan gadget multimedia iPhone dari pemilik merek gadget terpercaya, Apple.

Apalagi pada hasil RUPS Telkomsel yang berlangsung pertengahan Juni lalu, Telkomsel mengubah haluan AD/ART perusahaan untuk memperluas bisnis mereka ke arah multimedia. Hal ini dilakukan seiring dengan perubahan dan tantangan yang dialami Telkomsel dalam lingkungan bisnis.

Hanya saja, yang menjadi pertanyaan adalah kapan Telkomsel benar-benar akan mewujudkan hal tersebut.

→ 1 CommentCategories: AndZs Story
Tagged:

Remote desktop your Linux using Xmanager

June 17, 2008 · 4 Comments

It’s really helpful to remote your Linux. For example if your Linux is in Data Center where the place is so  cold  and there is  no ‘cozy’ place  for  you  to  install  and  configure  something  in your  Linux  that  need X11(Like install Oracle using Oracle Universal Installer).

To remote your Linux into your workstation you need software to remote your Linux, for now i choose Xmanager (Quite simple but “LICENSED” huh). There is other tool like VNC or XMing(I think i choose XManager because i’ve use it in my Solaris Box long time ago and always got good connection using it)

So to enable your Linux for remote desktop just follow this simple  instruction :

1. Open gdm.conf configuration file, usually located in /etc/X11/gdm/gdm.conf or /etc/gdm/custom.conf

2. Edit gdm.conf file, in section [gdcmp] change enable =  false  to  enable  =  true

3. Change run level to 5 in file /etc/inittab (example : x:5:once:/etc/X11/prefdm -nodaemon

4. Restart gdm service by simply run command : gdm-restart

5. Find your Xmanager source, installed it but not crack it.

PS : To enable X graphic open your terminal using root and type xhost +

Now let see my Linux Box in my workstation

→ 4 CommentsCategories: IT TipZzz
Tagged: , ,