Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • secure crt settings Linux/Unix
  • proper cpu stats Linux/Unix
  • configUOCIOTTO.ora Oracle
  • ORA-01220 Oracle
  • runsql_once.ksh Linux/Unix
  • The most important Tuning Notes Oracle
  • CTAS with LONG Column for 9i and higher Oracle
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • Backup and Recovery Scenarios Oracle
  • find_log_switch.sql Find log switches in graphical manner Oracle
  • Updated LCK.SQL file. Oracle
  • shr1.sql for MTS or Shared server configuration Oracle
  • move_arch_files.ksh Linux/Unix
  • Kernel Parameters for Solaris Linux/Unix
  • SYSOPER Mystery Oracle

get_vmstat_linux

Posted on 06-Jan-2009 By Admin No Comments on get_vmstat_linux

CREATE TABLE STATSUSER.STATS$TOTALUSERS

(

MEASURED_DATE DATE,

TOTAL_USERS NUMBER,

ACTIVE_USERS NUMBER,

UOCWEBSPHERE_USERS NUMBER,

UOCSCRIPTS_USERS NUMBER

);

CREATE TABLE STATSUSER.STATS$USERSESSIONS

(

START_DATE DATE,

SYSTEM_SESSIONS NUMBER,

ACTIVE_USERS NUMBER,

INACTIVE_USERS NUMBER,

DEDICATED_SERVERS NUMBER,

USER_SESSIONS NUMBER,

TRANSACTIONS NUMBER

);

CREATE INDEX STATSUSER.STATS$USERSESSIONS_STDTE_I ON STATSUSER.STATS$USERSESSIONS

(START_DATE);

/* Following procedure and shell program is for Solaris */

#!/bin/ksh

# This is the Linux version

ORACLE_SID=WEBP18F

export ORACLE_SID

ORACLE_HOME=/oracle/app/oracle/product/10.2

export ORACLE_HOME

PATH=$ORACLE_HOME/bin:$PATH

export PATH

SERVER_NAME=`uname -a|awk ‘{print $2}’`

typeset -u SERVER_NAME

export SERVER_NAME

# sample every five minutes (300 seconds) . . . .

SAMPLE_TIME=300

while true

do

vmstat ${SAMPLE_TIME} 2 > /tmp/msg$$

# run vmstat and direct the output into the Oracle table . . .

cat /tmp/msg$$|sed 1,3d | awk ‘{ printf(“%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %sn”, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) }’ | while read RUNQUE BUSY_WAITS SWAP FREE BUFF CACHE SWAP_IN SWAP_OUT BLOCKS_IN BLOCKS_OUT DEVICE_INTERRUPT CONTEXT_SWITCHES USER_CPU SYSTEM_CPU IDLE_CPU WAIT_CPU

do

# echo runqueue $RUNQUE

# echo busywaits $BUSY_WAITS

# echo swap $SWAP

# echo free $FREE

# echo buff $BUFF

# echo cache $CACHE

# echo swapin $SWAP_IN

# echo swapout $SWAP_OUT

# echo blockin $BLOCKS_IN

# echo blockout $BLOCKS_OUT

# echo int $DEVICE_INTERRUPT

# echo cs $CONTEXT_SWITCHES

# echo uc $USER_CPU

# echo sc $SYSTEM_CPU

# echo ic $IDLE_CPU

# echo wc $WAIT_CPU

$ORACLE_HOME/bin/sqlplus -s / < execute PERFSTAT.VMSTAT3(SYSDATE, $SAMPLE_TIME, ‘$SERVER_NAME’, $RUNQUE, $BUSY_WAITS, $SWAP, $FREE, $BUFF, $CACHE, $SWAP_IN, $SWAP_OUT, $BLOCKS_IN, $BLOCKS_OUT, $DEVICE_INTERRUPT, $CONTEXT_SWITCHES, $USER_CPU, $SYSTEM_CPU, $IDLE_CPU, $WAIT_CPU);

EXIT

EOF

done

done

rm /tmp/msg$$

create or replace PROCEDURE vmstat3

(START_DATE DATE, DURATION NUMBER, SERVER_NAME VARCHAR2,

RUNQUE NUMBER, BUSY_WAITS NUMBER, SWAP NUMBER,

FREE NUMBER, BUFF NUMBER, CACHE NUMBER,

SWAP_IN NUMBER, SWAP_OUT NUMBER, BLOCKS_IN NUMBER,

BLOCKS_OUT NUMBER, DEVICE_INTERRUPT NUMBER, CONTEXT_SWITCHES NUMBER,

USER_CPU NUMBER, SYSTEM_CPU NUMBER, IDLE_CPU NUMBER,

WAITS_CPU NUMBER)

AS

active_users number;

total_users number;

BEGIN

INSERT INTO PERFSTAT.STATS$VMSTAT2 VALUES

(START_DATE, DURATION , SERVER_NAME ,

RUNQUE, BUSY_WAITS , SWAP ,

FREE, BUFF , CACHE ,

SWAP_IN, SWAP_OUT , BLOCKS_IN ,

BLOCKS_OUT, DEVICE_INTERRUPT , CONTEXT_SWITCHES ,

USER_CPU, SYSTEM_CPU , IDLE_CPU ,

WAITS_CPU );

select count(*) into active_users From v$session where username <> ‘ ‘ and status = ‘ACTIVE’;

select count(*) into total_users From v$session where username <> ‘ ‘ ;

INSERT INTO PERFSTAT.STATS$TOTALUSERS

(measured_date,total_users,active_users)

values

(START_DATE,total_users,active_users);

INSERT INTO PERFSTAT.STATS$USERSESSIONS select sysdate,sum(decode(type,’BACKGROUND’,1,0)) system_sessions,

sum(decode(type,’BACKGROUND’,0,decode(status,’ACTIVE’,1,0))) active_users,

sum(decode(type,’BACKGROUND’,0,decode(status,’ACTIVE’,0,1))) inactive_users,

sum(decode(type,’BACKGROUND’,0,decode(server,’DEDICATED’,1,0))) dedicated_servers,

sum(decode(type,’BACKGROUND’,0,1)) user_sessions,

sum(decode(taddr,”,0,decode(status,’ACTIVE’,1,0))) transactions

from v$session;

commit;

END;

Oracle, SQL scripts

Post navigation

Previous Post: get_vmstat_solaris
Next Post: DBMS_SQL for alter session.

Related Posts

  • FRA Information. Oracle
  • export import with parameter file. Oracle
  • Oracle 10g Wait Model Oracle
  • TRUNCATE Privs Oracle
  • mutex in Oracle 10.2.0.2 or Oracle 10g Oracle
  • database trigger failing Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (387)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (336)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024
  • Reading config file from other folder inside class24-Sep-2024
  • Python class import from different folders22-Sep-2024
  • Transfer SQL Profiles from One database to other database.05-Sep-2024
  • Load testing on Oracle 19C RAC with HammerDB18-Jan-2024
  • Add new columns in dataframe30-Sep-2023

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • sqlnet.ora paramters Oracle
  • Oracle Data Direct to TAPE Oracle
  • oracle Dba site Oracle
  • Rownum with Order by Oracle
  • DBMS_STATS Metalinks Notes Oracle
  • initUOCIOTTO.ora Oracle
  • fkwoindex.sql /* Find FK without Index */ Oracle
  • Composite Index creation tip from Vivek Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme