How To find out largest 10 tables in Mysql database

mysql> SELECT CONCAT(table_schema, '.', table_name),
    ->        CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
    ->        CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
    ->        CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
    ->        CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
    ->        ROUND(index_length / data_length, 2)                                           idxfrac
    -> FROM   information_schema.TABLES
    -> ORDER  BY data_length + index_length DESC
    -> LIMIT  10;


+-------------------------------------------+-------+-------+-------+------------+---------+
| CONCAT(table_schema, '.', table_name)     | rows  | DATA  | idx   | total_size | idxfrac |
+-------------------------------------------+-------+-------+-------+------------+---------+
| test.sg_postmeta                     | 0.38M | 0.03G | 0.02G | 0.05G      |    0.62 |
| primary_prod.log_url_info                | 0.34M | 0.04G | 0.00G | 0.04G      |    0.00 |
| primary_prod.log_visitor_info            | 0.24M | 0.04G | 0.00G | 0.04G      |    0.00 |
| primary_prod.log_url                     | 0.33M | 0.01G | 0.01G | 0.03G      |    0.97 |
| primary_prod.log_visitor                 | 0.26M | 0.02G | 0.00G | 0.02G      |    0.00 |
| test.sg_posts                       | 0.05M | 0.01G | 0.01G | 0.01G      |    0.81 |
| primary_prod.report_event                | 0.05M | 0.00G | 0.01G | 0.01G      |    3.01 |
| primary_prod.report_viewed_product_index | 0.03M | 0.00G | 0.01G | 0.01G      |    2.88 |
| crm.vtiger_profile2field                  | 0.03M | 0.00G | 0.00G | 0.01G      |    3.00 |
| crm.vtiger_role2picklist                  | 0.01M | 0.00G | 0.00G | 0.00G      |    0.57 |
+-------------------------------------------+-------+-------+-------+------------+---------+
10 rows in set (1.07 sec)

Monitoring Data Guard Log Shipping using Shell Script with Mail alert

Version:- Oracle 11g
All the below scripts are stored and will run from oracle user & from Primary Database.

[oracle@server1 ~]$ vi /home/oracle/dg.sql
Set linesize 140
set head off
SELECT DB_NAME, HOSTNAME, LOG_ARCHIVED, LOG_APPLIED,APPLIED_TIME,
LOG_ARCHIVED-LOG_APPLIED LOG_GAP
FROM
(SELECT NAME DB_NAME FROM V$DATABASE),
(SELECT UPPER(SUBSTR(HOST_NAME,1,(DECODE(INSTR(HOST_NAME,'.'),0,LENGTH(HOST_NAME),(INSTR(HOST_NAME,'.')-1))))) HOSTNAME FROM V$INSTANCE
),
(SELECT MAX(SEQUENCE#) LOG_ARCHIVED FROM V$ARCHIVED_LOG WHERE DEST_ID=1 AND ARCHIVED='YES' ),
(SELECT MAX(SEQUENCE#) LOG_APPLIED FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES' ),
(SELECT TO_CHAR(MAX(COMPLETION_TIME),'DD-MON/HH24:MI') APPLIED_TIME FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND APPLIED='YES');
exit;

:wq

Now lets create the shell-script which will monitor the log gap in between of primary and standby database:-
From oracle user.
[oracle@server1 ~]$ vi /home/oracle/dgmonitor.sh
sqlplus -S / as sysdba @/home/oracle/dg.sql > /home/oracle/loggap.txt
loggap=`cat /home/oracle/loggap.txt | awk '{print $6}'`
if [ $loggap -ne 0 ]; then
mail -s "Attention!! There is a loggap between Primary and Standby Database! " yourmailid@gmail.com
fi
exit 0

:wq

[oracle@server1 ~]$ chmod 777 dgmonitor.sh

Now schedule it on crontab to execute the script for every 15mins :-
[oracle@server1 ~]$  crontab -e
*/15 * * * * /home/oracle/dgmonitor.sh > /dev/null

Related Posts Plugin for WordPress, Blogger...