Script to count the dataflow in a table in oracle database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to count the dataflow in a table in oracle database
# 1  
Old 03-06-2012
Script to count the dataflow in a table in oracle database

I need to write a unix shell script to connect to oracle database and retrieve data from a table, the script should count the total number of rows till date in that table
number of rows which are getting filled per hour on current day and the peak hour of the current day
number of rows which are getting filled per day and per week

This is to be done for multiple tables

This count helps me in calculating the dataflow per hour,day,week


Thanks in advance
# 2  
Old 03-06-2012
I'm not a DBA, but this kind of thing is available in products like Spotlight and Toad.
What you are asking for is database I/O, and I do not believe this is available on anything more fine-grained than a tablespace. Many tables can live in a tablespace. If your table is the only one in its tablespace you may be in luck.

And unless your table has an actively maintained "activity_date" column (timestamp or sysdate) you will never get insert rates, except going forward.
# 3  
Old 03-07-2012
Each table has actively maintained date column and I use toad to connect to oracle database.
Is there any way to find out that the certain table is the only table in the tablespace?
# 4  
Old 03-07-2012
You may can find with the help of DBA_TABLES (view) the table which is placed in the tablespace.

Calculating the dataflow per hour,day,week?
---Check the logswitches per day with given below query hope it will helpfull.
Note:- It will not give you insertion,deletion,updation of the data.but gives you total transction of the database.
Code:
#####################################################
-- Author : Mohammed Fareed.
-- Script : log_switch.sql
-- Description : Get log switches on total , daily and hourly basis 
set heading off;
select '******************************************************' from dual;
select '****  Redolog Daily and Hourly volume calculated  ****' from dual;
select '******************************************************' from dual;
timing start Redovol;

--#######################################################################################
--##           PL/SQL used here to gather and display average redo volumes             ##
--#######################################################################################
set serveroutput on;
declare
v_log    number;
v_days   number;
v_logsz  number;
v_adsw   number;
V_advol  number;
v_ahsw   number;
v_ahvol  number;

begin
select count(first_time) into v_log from v$log_history;
select count(distinct(to_char(first_time,'dd-mon-rrrr'))) into v_days from v$log_history;
select max(bytes)/1024/1024 into v_logsz from v$log;
v_adsw := round(v_log / v_days);
v_advol := round(v_adsw * v_logsz);
v_ahsw := round(v_adsw / 24);
v_ahvol := round((v_adsw / 24 )) * v_logsz;
dbms_output.put ('Total Switches' || ' '||v_log||'  ==>  ');
dbms_output.put ('Total Days' || ' '|| v_days||'  ==>  ');
dbms_output.put_line ('Redo Size' || ' ' || v_logsz);
dbms_output.put ('Avg Daily Switches' || ' ' || v_adsw||'  ==>  ');
dbms_output.put_line ('Avg Daily Volume in Meg' || ' ' || v_advol);
dbms_output.put ('Avg Hourly Switches' || ' ' || v_ahsw||'  ==>  ');
dbms_output.put_line ('Avg Hourly Volume in Meg' || ' ' || v_ahvol);

end;
/
--#######################################################################################
--##                                                  END of PL/SQL routine            ##
--#######################################################################################
 
timing stop Redovol;
 
###########################################################


Last edited by Franklin52; 03-07-2012 at 05:12 AM.. Reason: Please use code tags for code and data samples, thank you
Mohammed Fareed
# 5  
Old 03-07-2012
Quote:
Originally Posted by PhAnT0M
Each table has actively maintained date column and I use toad to connect to oracle database.
Is there any way to find out that the certain table is the only table in the tablespace?
You can view the contents of your tablespaces in TOADs schema browser or query your database for it:
Code:
SELECT tablespace_name,table_name 
  FROM user_tables;

To count inserted rows you need a list of tables you'd like to anylse and the names of the date-columns. I'd put them in a file like this:
Code:
tablename1:datecolumnname1
tablename2:datecolumnname2
...

Then a simple script can read that file and query your database:
Code:
TABLE_DEF=/path/to/your/file.that.lists.tables.and.datecolumns
DB_USER=your_db_user
DB_PASSWORD=your_password

OLD_IFS=$IFS
IFS=:
while read TABLE_NAME DATE_COLUMN
do
   sqlplus -s $DB_USER/$DB_PASSWORD@$ORACLE_SID <<EOF
set heading off
set feedback off
prompt Dataflow for table $TABLE_NAME
select 'Total number of rows',count(*)
  from $TABLE_NAME;
select 'Number of rows inserted today',count(*)
  from $TABLE_NAME
 where trunc($DATE_COLUMN) = trunc(sysdate);
prompt Number of rows per hour today, peak hour first
set heading on
select to_char($DATE_COLUMN,'HH24') "hr",count(*) "rows inserted"
  from $TABLE_NAME
 where trunc($DATE_COLUMN) = trunc(sysdate)
 group by to_char($DATE_COLUMN,'HH24')
 order by 2 desc;
set heading off
select 'Number of rows inserted this week',count(*)
  from $TABLE_NAME
 where trunc($DATE_COLUMN,'IW') = trunc(sysdate,'IW');
EOF
done <$TABLE_DEF
IFS=$OLD_IFS

# 6  
Old 03-07-2012
Its giving me error saying Table or View doesn't exist
I gave all the correct table details
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Intelligent Script to Insert Records in Database Table

Hello All Members, I am new to this forum and to the shell scripting. I want to write a shell script to do the following: Scenario: I have a pipe delimited .txt file with multiple fields in it. The very first row of the file contains the name of the column which resembles the name of the... (18 Replies)
Discussion started by: chetanojha
18 Replies

2. Shell Programming and Scripting

UNIX Script required for count the records in table

Hi Friends, I looking for the script for the count of the records in table. and then it's containg the zero records then should get abort. and should notify us through mail. Can you please help me out in this area i am lacking. (5 Replies)
Discussion started by: victory
5 Replies

3. Shell Programming and Scripting

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

4. Shell Programming and Scripting

Sample ksh script for copy the data from excel to database table ?

Hi All, I need to convert the data from excel to database table in sybase. Please provide some sample script.. thanks, Royal. (1 Reply)
Discussion started by: royal9482
1 Replies

5. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

6. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

7. HP-UX

to create a oracle table in perl script

Hi all, I have to create table for each month inside a perl script. tablename_monthnameyear. megh_aug2008 for august 2008. megh_sep2008 for september 2008. just like the logfiles created on date basis. thanks megh (1 Reply)
Discussion started by: megh
1 Replies

8. UNIX for Advanced & Expert Users

Delete database table based on months using script.

HI All, Newbie here. I have a script which generates the tables in teradata database with time stamp like below.I want to add some more code to delete the archive tables which are 2months old. . $HOME/.profile t_name=$1 procdate=`date +%y%m%d` log_dir=$Folder/log tab=`echo... (0 Replies)
Discussion started by: Maverick79
0 Replies

9. Shell Programming and Scripting

update a oracle table using shell script

Hi, I would like to know how to update a table in Oracle database, if a command in one shell script either successfully completes or it fails.(like Y if its success or N if its a failure) While the command is running,I am able to view the log file created in the Unix machine.After the command... (2 Replies)
Discussion started by: ann_124
2 Replies

10. Shell Programming and Scripting

export table from oracle database

i would like to export a particular table in my oracle database installed in a hpux box. i would like to determine the filesize of the output before performing these action so i can assess if my harddisk can still handle it. thanks as usuall :rolleyes: (1 Reply)
Discussion started by: inquirer
1 Replies
Login or Register to Ask a Question