[Shell] Linux monitor tablespace usage
linux monitor tablespace
1.create database link
先賦予create database link的許可權
SQL> grant create database link to mon;
Grant succeeded.
SQL> create database link yangxu connect to system identified by xxxxx_123 using 'yangxu';
Database link created.
2.create table
SQL> create table mon_tablespace(
2 dbid varchar2(20),
3 dbname varchar2(20),
4 tablespace_name varchar2(24),
5 total_size int,
6 free_size int,
7 use_size int,
8 usage number(5,2),
9 mon_date date
10 );
Table created
3.create view
查詢相關資訊
SQL> grant create view to mon;
Grant succeeded.
SQL> create view v_mon_tablespace
2 as
3 select
4 (select dbid from v$database) dbid,
5 (select name from v$database) dbname,
6 x.tablespace_name,y.bytes total_size,x.bytes free_size,(y.bytes-x.bytes) use_size,round((y.bytes-x.bytes)/y.bytes,4)*100 usage,
7 sysdate as mon_date
8 from
9 (select tablespace_name,sum(bytes) bytes from dba_free_space group by tablespace_name) x,
10 (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) y
11 where x.tablespace_name=y.tablespace_name
12 order by 7 desc;
4.Shell script
[mon@oracle6 source]$ cat mon_tablespace
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=xxxxxdb
DATETIME=`date +"%Y/%m/%d %H:%M:%S"`
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_tablespace.log
insert into mon_tablespace select * from v_mon_tablespace;
commit;
exit;
EOF
STRS="topaz yangxu standby abcd"
for STR in $STRS
do
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_tablespace.log
insert into mon_tablespace
select
(select dbid from v\$database@$STR) dbid,
(select name from v\$database@$STR) dbname,
x.tablespace_name,y.bytes total_size,x.bytes free_size,(y.bytes-x.bytes) use_size,round((y.bytes-x.bytes)/y.bytes,4)*100 usage,
sysdate mon_date
from
(select tablespace_name,sum(bytes) bytes from dba_free_space@$STR group by tablespace_name) x,
(select tablespace_name,sum(bytes) bytes from dba_data_files@$STR group by tablespace_name) y
where x.tablespace_name=y.tablespace_name
order by 7 desc;
commit;
exit
EOF
#echo "STR:$STR"
done
5.crontab定時任務
[mon@oracle6 source]$ crontab -l
55 7,16 * * * /home/mon/source/mon_tablespace > /dev/null 2>&1
1.create database link
先賦予create database link的許可權
SQL> grant create database link to mon;
Grant succeeded.
SQL> create database link yangxu connect to system identified by xxxxx_123 using 'yangxu';
Database link created.
2.create table
SQL> create table mon_tablespace(
2 dbid varchar2(20),
3 dbname varchar2(20),
4 tablespace_name varchar2(24),
5 total_size int,
6 free_size int,
7 use_size int,
8 usage number(5,2),
9 mon_date date
10 );
Table created
3.create view
查詢相關資訊
SQL> grant create view to mon;
Grant succeeded.
SQL> create view v_mon_tablespace
2 as
3 select
4 (select dbid from v$database) dbid,
5 (select name from v$database) dbname,
6 x.tablespace_name,y.bytes total_size,x.bytes free_size,(y.bytes-x.bytes) use_size,round((y.bytes-x.bytes)/y.bytes,4)*100 usage,
7 sysdate as mon_date
8 from
9 (select tablespace_name,sum(bytes) bytes from dba_free_space group by tablespace_name) x,
10 (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) y
11 where x.tablespace_name=y.tablespace_name
12 order by 7 desc;
4.Shell script
[mon@oracle6 source]$ cat mon_tablespace
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=xxxxxdb
DATETIME=`date +"%Y/%m/%d %H:%M:%S"`
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_tablespace.log
insert into mon_tablespace select * from v_mon_tablespace;
commit;
exit;
EOF
STRS="topaz yangxu standby abcd"
for STR in $STRS
do
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_tablespace.log
insert into mon_tablespace
select
(select dbid from v\$database@$STR) dbid,
(select name from v\$database@$STR) dbname,
x.tablespace_name,y.bytes total_size,x.bytes free_size,(y.bytes-x.bytes) use_size,round((y.bytes-x.bytes)/y.bytes,4)*100 usage,
sysdate mon_date
from
(select tablespace_name,sum(bytes) bytes from dba_free_space@$STR group by tablespace_name) x,
(select tablespace_name,sum(bytes) bytes from dba_data_files@$STR group by tablespace_name) y
where x.tablespace_name=y.tablespace_name
order by 7 desc;
commit;
exit
EOF
#echo "STR:$STR"
done
5.crontab定時任務
[mon@oracle6 source]$ crontab -l
55 7,16 * * * /home/mon/source/mon_tablespace > /dev/null 2>&1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2021922/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle11g新增檢視查詢表空間使用率DBA_TABLESPACE_USAGE_METRICSOracle
- Linux ShellLinux
- dnsjava usageDNSJava
- crontab usage guideGUIIDE
- Linux shell日常使用Linux
- Linux Shell變數Linux變數
- Linux Shell指令碼Linux指令碼
- Oracle OCP(48):UNDO TABLESPACEOracle
- MySQL 5.7 InnoDB Tablespace EncryptionMySql
- Linux 核心、Shell 簡述Linux
- Linux的shell環境Linux
- 【Linux shell】while read lineLinuxWhile
- Linux中vim和shellLinux
- Linux shell命令總結Linux
- Linux 修改 預設 shellLinux
- linux shell特殊引數Linux
- Linux之shell變數Linux變數
- Linux shell基礎3Linux
- Linux shell基礎1Linux
- Linux shell基礎2Linux
- linux Shell 命令列-03-array Shell 陣列Linux命令列陣列
- 什麼是shell?Linux常用的shell有哪些?Linux
- 什麼是Shell?Linux shell分為幾類?Linux
- 在Linux中,什麼是Linux shell?Linux
- MySQL, Incorrect usage of UNION and ORDER BYMySql
- SAP QM Auto Usage Decision
- Inspection Points: Key settings and Usage
- 2788647047_monitor
- Tablespace表空間刪除
- Linux shell:執行shell指令碼的幾種方式Linux指令碼
- 什麼是shell?Linux中shell有什麼用途?Linux
- Linux下Shell日期的格式Linux
- Linux之shell程式設計Linux程式設計
- linux常用的shell指令碼Linux指令碼
- Linux shell必知必會Linux
- 【linux】Shell中的運算子Linux
- Linux Shell程式設計(1)Linux程式設計
- Linux Shell程式設計(2)Linux程式設計
- Postman的Monitor功能Postman