[原創] 利用Oracle metric(threshold)監控表空間
在10g中引入了metric,不但可以調化資料庫,還可以用來監控資料庫,如下
1.建立測試表空間
SYS@dbatest>create tablespace TBS_YXYUP datafile '/u01/oracle/oradata/dbatest/tbs_yxyup01.dbf' size 10m;
Tablespace created.
Elapsed: 00:00:01.09
2.確認現有metric
SYS@dbatest>select count(1) from dba_thresholds;
COUNT(1)
----------
22
Elapsed: 00:00:00.04
3.建立新的metric
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold(
3 dbms_server_alert.tablespace_pct_full,
4 dbms_server_alert.operator_ge, 80,
5 dbms_server_alert.operator_ge, 95, 1, 1, NULL,
6 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
7 END;
8 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
4.檢視新建立的metric
SYS@dbatest>select count(1) from dba_thresholds;
COUNT(1)
----------
23
Elapsed: 00:00:00.01
Elapsed: 00:00:00.00
SYS@dbatest>col warning_value format a20
SYS@dbatest>col critical_value format a20
SYS@dbatest>
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
WARNING_VALUE CRITICAL_VALUE STATUS
-------------------- -------------------- -------
80 95 VALID
Elapsed: 00:00:00.00
SYS@dbatest>
5.模擬資料增長,達到threshold
YXYUP@dbatest>drop table t3 purge;
Table dropped.
Elapsed: 00:00:00.10
YXYUP@dbatest>create table t3 tablespace tbs_YXYUP as select * from dba_objects;
Table created.
Elapsed: 00:00:00.90
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.02
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.00
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.02
YXYUP@dbatest>r
1* insert into t3 select * from t3 where rownum<4001
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.03
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.01
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.03
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.01
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.00
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.02
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.01
YXYUP@dbatest>
SYS@dbatest>select sum(bytes)/1024/1024 from dba_segments where segment_name='T3'
SUM(BYTES)/1024/1024
--------------------
9
6. 檢視是否生效
SYS@dbatest>col REASON for a50;
SYS@dbatest>SELECT reason, message_level,
2 DECODE(message_level, 5, 'WARNING', 1, 'CRITICAL') ALERT_LEVEL
3 FROM dba_outstanding_alerts
4 WHERE object_name = 'TBS_YXYUP';
REASON MESSAGE_LEVEL ALERT_LE
-------------------------------------------------- ------------- --------
Tablespace [TBS_YXYUP] is [90 percent] full 5 WARNING
7.停用metric
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold (
3 dbms_server_alert.tablespace_pct_full,
4 dbms_server_alert.operator_do_not_check, '0',
5 dbms_server_alert.operator_do_not_check, '0', 1, 1, NULL,
6 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
7 END;
8 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
WARNING_VALUE CRITICAL_VALUE STATUS
-------------------- -------------------- -------
0 0 VALID
8.取消metric(threshold)
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold (
3 dbms_server_alert.tablespace_pct_full,
4 NULL, NULL, NULL, NULL, 1, 1, NULL,
5 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
6 END;
7 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
no rows selected
Elapsed: 00:00:00.01
SYS@dbatest>
1.建立測試表空間
SYS@dbatest>create tablespace TBS_YXYUP datafile '/u01/oracle/oradata/dbatest/tbs_yxyup01.dbf' size 10m;
Tablespace created.
Elapsed: 00:00:01.09
2.確認現有metric
SYS@dbatest>select count(1) from dba_thresholds;
COUNT(1)
----------
22
Elapsed: 00:00:00.04
3.建立新的metric
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold(
3 dbms_server_alert.tablespace_pct_full,
4 dbms_server_alert.operator_ge, 80,
5 dbms_server_alert.operator_ge, 95, 1, 1, NULL,
6 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
7 END;
8 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
4.檢視新建立的metric
SYS@dbatest>select count(1) from dba_thresholds;
COUNT(1)
----------
23
Elapsed: 00:00:00.01
Elapsed: 00:00:00.00
SYS@dbatest>col warning_value format a20
SYS@dbatest>col critical_value format a20
SYS@dbatest>
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
WARNING_VALUE CRITICAL_VALUE STATUS
-------------------- -------------------- -------
80 95 VALID
Elapsed: 00:00:00.00
SYS@dbatest>
5.模擬資料增長,達到threshold
YXYUP@dbatest>drop table t3 purge;
Table dropped.
Elapsed: 00:00:00.10
YXYUP@dbatest>create table t3 tablespace tbs_YXYUP as select * from dba_objects;
Table created.
Elapsed: 00:00:00.90
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.02
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.00
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.02
YXYUP@dbatest>r
1* insert into t3 select * from t3 where rownum<4001
4000 rows created.
Elapsed: 00:00:00.03
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.03
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.01
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.03
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.01
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.00
YXYUP@dbatest>insert into t3 select * from t3 where rownum<4001 ;
4000 rows created.
Elapsed: 00:00:00.02
YXYUP@dbatest>commit;
Commit complete.
Elapsed: 00:00:00.01
YXYUP@dbatest>
SYS@dbatest>select sum(bytes)/1024/1024 from dba_segments where segment_name='T3'
SUM(BYTES)/1024/1024
--------------------
9
6. 檢視是否生效
SYS@dbatest>col REASON for a50;
SYS@dbatest>SELECT reason, message_level,
2 DECODE(message_level, 5, 'WARNING', 1, 'CRITICAL') ALERT_LEVEL
3 FROM dba_outstanding_alerts
4 WHERE object_name = 'TBS_YXYUP';
REASON MESSAGE_LEVEL ALERT_LE
-------------------------------------------------- ------------- --------
Tablespace [TBS_YXYUP] is [90 percent] full 5 WARNING
7.停用metric
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold (
3 dbms_server_alert.tablespace_pct_full,
4 dbms_server_alert.operator_do_not_check, '0',
5 dbms_server_alert.operator_do_not_check, '0', 1, 1, NULL,
6 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
7 END;
8 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
WARNING_VALUE CRITICAL_VALUE STATUS
-------------------- -------------------- -------
0 0 VALID
8.取消metric(threshold)
SYS@dbatest>BEGIN
2 dbms_server_alert.set_threshold (
3 dbms_server_alert.tablespace_pct_full,
4 NULL, NULL, NULL, NULL, 1, 1, NULL,
5 dbms_server_alert.object_type_tablespace, 'TBS_YXYUP');
6 END;
7 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
SYS@dbatest>SELECT warning_value, critical_value, status
2 FROM dba_thresholds
3 WHERE metrics_name = 'Tablespace Space Usage'
4 AND object_name = 'TBS_YXYUP';
no rows selected
Elapsed: 00:00:00.01
SYS@dbatest>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-1136704/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle sql 表空間利用率OracleSQL
- oracle 表空間Oracle
- Oracle表空間Oracle
- oracle temp 表空間Oracle
- 增加oracle表空間Oracle
- 表空間利用率及表空間的補充
- oracle 表移動表空間Oracle
- Oracle表移動表空間Oracle
- oracle表空間的整理Oracle
- Oracle 批量建表空間Oracle
- Oracle清理SYSAUX表空間OracleUX
- Oracle 表空間增加檔案Oracle
- Oracle OCP(49):表空間管理Oracle
- Oracle RMAN 表空間恢復Oracle
- Oracle Temp 表空間切換Oracle
- Oracle表空間收縮方案Oracle
- Oracle新建使用者、表空間、表Oracle
- oracle建立臨時表空間和資料表空間以及刪除Oracle
- oracle臨時表空間相關Oracle
- 【Oracle 恢復表空間】 實驗Oracle
- 【TABLESPACE】Oracle表空間最佳實踐Oracle
- Oracle OCP(47):表空間的建立Oracle
- Oracle的表空間quota詳解Oracle
- Skywalking-04:擴充套件Metric監控資訊套件
- Oracle中新建表空間、使用者Oracle
- Oracle建立表空間和使用者Oracle
- Oracle中表空間、表、索引的遷移Oracle索引
- ORACLE線上切換undo表空間Oracle
- 【TABLESPACE】Oracle 表空間結構說明Oracle
- oracle表空間增長趨勢分析Oracle
- Oracle OCP(46):表空間、段、區、塊Oracle
- Oracle RAC+DG 表空間擴容Oracle
- oracle表空間使用率查詢Oracle
- oracle 建立表空間和使用者Oracle
- 16、表空間 建立表空間
- Oracle臨時表空間檢視、新增臨時表空間資料檔案、修改預設臨時表空間 方法!Oracle
- ? Hyperf 釋出 v1.1.4 版本,增加 Metric 監控元件元件
- 【TABLE】Oracle監控異常的表設計Oracle
- 【RESIZE】Oracle收縮表空間主要命令Oracle