Metrics in Oracle 19c provide essential insights into the performance and health of your database. By monitoring these metrics, database administrators (DBAs) can detect issues early, optimize resource usage, and ensure smooth database operations. This entry explores key metrics views such as V$METRIC
, V$SYSMETRIC
, and V$METRIC_HISTORY
, provides examples of setting alert thresholds, and discusses the most useful types of metrics and their applications.
Key Metrics Views in Oracle 19c
Oracle 19c offers several dynamic views that store and present performance metrics. Understanding these views is crucial for effective database monitoring.
V$METRIC
V$METRIC
provides real-time performance data collected at short intervals, typically every minute. This view is ideal for tracking the immediate performance of your database, offering granular insights into various system activities.
SELECT METRIC_NAME, VALUE, BEGIN_TIME, END_TIME FROM V$METRIC WHERE METRIC_NAME = 'CPU Usage Per Sec' ORDER BY BEGIN_TIME DESC;
This query retrieves recent CPU usage data, which can be crucial when diagnosing sudden spikes in resource usage.
V$SYSMETRIC
V$SYSMETRIC
is similar to V$METRIC
but typically aggregates data over slightly longer intervals, providing a broader view of system performance. It’s particularly useful for analyzing trends over time rather than minute-by-minute changes.
SELECT METRIC_NAME, VALUE FROM V$SYSMETRIC WHERE METRIC_NAME = 'Database Wait Time Ratio';
This query returns the current value for the Database Wait Time Ratio, helping identify potential I/O bottlenecks.
V$METRIC_HISTORY
V$METRIC_HISTORY
stores historical metric data, allowing DBAs to analyze trends and compare performance over time. This view is essential for understanding how performance metrics evolve and identifying persistent issues.
SELECT METRIC_NAME, VALUE, BEGIN_TIME, END_TIME FROM V$METRIC_HISTORY WHERE METRIC_NAME = 'DB Time Per Sec' AND BEGIN_TIME > SYSDATE - 1 ORDER BY BEGIN_TIME;
This query retrieves historical data for the DB Time Per Sec
metric from the last day, which is useful for analyzing database performance over time.
Setting Alert Thresholds for Metrics
One of the practical applications of monitoring metrics is setting alert thresholds. This allows you to automate the detection of potential issues before they become critical.
Oracle provides the DBMS_SERVER_ALERT.SET_THRESHOLD
procedure to set these thresholds. Here’s an example:
BEGIN DBMS_SERVER_ALERT.SET_THRESHOLD( metrics_id => DBMS_SERVER_ALERT.TABLESPACE_PCT_FULL, warning_operator => DBMS_SERVER_ALERT.OPERATOR_GT, warning_value => '80', critical_operator => DBMS_SERVER_ALERT.OPERATOR_GT, critical_value => '95', observation_period => 1, consecutive_occurrences => 1, instance_name => NULL, object_type => DBMS_SERVER_ALERT.OBJECT_TYPE_TABLESPACE, object_name => 'USERS' -- Replace with your tablespace name ); END; /
This script sets a warning threshold when the USERS
tablespace exceeds 80% capacity, and a critical alert at 95%. This helps in proactive management of tablespace usage, ensuring that space issues are addressed before they impact database operations.
Most Useful Types of Metrics
Certain metrics are particularly useful for maintaining a healthy database environment. Below are some key types:
1. CPU Usage Metrics
Metrics such as CPU Usage Per Sec
help in monitoring how much CPU resources the database is consuming. High CPU usage can indicate inefficient queries or inadequate hardware resources.
2. I/O Metrics
Metrics like Database Wait Time Ratio
and Physical Reads Per Sec
are vital for understanding how efficiently the database is handling I/O operations. Persistent high wait times or read rates can suggest underlying storage issues or poorly optimized queries.
3. Memory Usage Metrics
Metrics such as Buffer Cache Hit Ratio
are crucial for ensuring that the database is efficiently using its memory. A low hit ratio could indicate that the database is frequently reading data from disk rather than memory, which can slow down performance.
4. Session Activity Metrics
Monitoring metrics like Session Count
helps in understanding the load on your database. An unusually high number of sessions might suggest a need to increase the capacity or optimize application connections.
Use Cases for Metrics
1. Diagnosing Performance Issues
When users report slow database performance, metrics such as DB Time Per Sec
or CPU Usage Per Sec
provide immediate insights into potential bottlenecks, allowing DBAs to quickly identify and resolve the issue.
2. Capacity Planning
By analyzing metrics like Tablespace Usage
and Sessions Highwater
, DBAs can predict when additional resources will be needed and plan capacity upgrades accordingly.
3. Proactive Monitoring
Setting up alert thresholds based on metrics ensures that DBAs are notified of issues before they escalate. For example, receiving an alert when CPU usage exceeds a certain threshold allows you to investigate and mitigate the issue before it affects users.
More on use cases:
The main types of metrics that can be monitored with DBMS_SERVER_ALERT
in Oracle 19c cover various critical aspects of database performance and management.
For tablespace usage, metrics such as TABLESPACE_PCT_FULL
monitor the percentage of space used, helping to prevent tablespaces from filling up and causing database issues. Similarly, TABLESPACE_PCT_INCREASE
tracks the rate of space usage growth, detecting rapid or abnormal increases that could indicate underlying problems.
Session activity metrics like SESSIONS_CURRENT
keep an eye on the number of active sessions, which is useful for identifying system overloads due to excessive connections. The SESSIONS_HIGHWATER
metric monitors the historical peak of connected sessions, aiding in capacity planning and analyzing usage spikes.
CPU usage is tracked by metrics such as CPU_PER_SEC
, which monitors CPU usage per second to detect if any process or the database itself is consuming too much CPU time, potentially affecting system performance. Another metric, CPU_PER_CALL
, focuses on CPU usage per database call, helping to identify queries or procedures that may be excessively resource-intensive.
Redo log metrics, including REDO_TBLSPC_SIZE
, monitor the size of the redo log tablespace to ensure sufficient space is available, which is crucial for database recovery. REDO_TBLSPC_PCT_FULL
checks the percentage of space used in the redo logs, preventing situations where the logs might fill up, potentially halting database operations.
Wait event metrics, like DB_BLOCK_CHANGES_PER_SEC
, monitor the rate of database block changes, which can indicate high write activity and possible system stress. DB_FILE_IO_WAITS
tracks file I/O wait times, identifying latency issues that could degrade database performance.
Undo operations are monitored by UNDO_BLKS_PER_SEC
, which tracks the number of undo blocks generated per second, ensuring undo operations stay within expected limits, essential for transaction efficiency. The UNDO_TBLSPC_SIZE
metric monitors the size of the undo tablespace, preventing it from filling up, which could otherwise lead to transaction handling issues.
In terms of buffer cache performance, BUFFER_CACHE_HIT_RATIO
measures the hit ratio in the buffer cache, a key indicator of cache efficiency. A low hit ratio might suggest the need to adjust the cache size. Additionally, LATCH_HIT_RATIO
monitors the latch hit ratio, where a low ratio could indicate contention issues within the database’s memory management.
Lastly, the ROLLBACK_SEGMENT_AVAIL
metric monitors the availability of rollback segments, ensuring they are available when needed, which is crucial for proper transaction management.
These metrics are invaluable for DBAs to maintain optimal database performance, prevent potential issues, and efficiently manage resources.
Conclusion
Metrics in Oracle 19c are invaluable tools for monitoring and maintaining the performance and health of your database. By leveraging views like V$METRIC
, V$SYSMETRIC
, and V$METRIC_HISTORY
, and setting appropriate alert thresholds, DBAs can ensure their databases run smoothly and efficiently. Understanding and using these metrics effectively can make the difference between a well-tuned system and one that constantly battles performance issues.