The V$SYSSTAT view is a powerful tool that can be used to monitor the performance of an Oracle database. By understanding the statistics in this view, you can identify potential problems and bottlenecks, and take steps to improve the performance of your database.
First Query sums the various statistics value in a single select from `v$sysstat`.
SELECT a.value + b.value "logical_reads",
c.value "phys_reads",
d.value "phys_writes",
ROUND(100 * ((a.value + b.value) - c.value) / (a.value + b.value))
"BUFFER HIT RATIO"
FROM v$sysstat a, v$sysstat b, v$sysstat c, v$sysstat d
WHERE a.statistic# = 37
AND b.statistic# = 38
AND c.statistic# = 39
AND d.statistic# = 40;
- Compatibility: This query is valid for Oracle 19c. The v$sysstat dynamic performance view and its statistic# column remain available in Oracle 19c.
- Potential issues: Ensure that the statistics IDs (statistic#) provided (37, 38, 39, 40) are valid in the Oracle 19c environment. These IDs map to specific metrics, and if the mapping has changed in 19c, the query may not return the expected results.
This query calculates the buffer hit ratio, which is an important metric for database performance.
Second Query: The second query joins the `v$sysstat` table against itself (4 times).
prompt ***********************
prompt Hit Ratio Section
prompt ***********************
prompt ========================
prompt BUFFER HIT RATIO
prompt ========================
prompt (should be > 70, else increase db_block_buffers in init.ora)
SELECT TRUNC(
(1 - (SUM(DECODE(name, 'physical reads', value, 0)) /
(SUM(DECODE(name, 'db block gets', value, 0)) +
SUM(DECODE(name, 'consistent gets', value, 0)))))
) * 100
"Buffer Hit Ratio"
FROM v$sysstat;
- Compatibility: This query uses the DECODE function and performs aggregate operations (SUM). These functions and the v$sysstat view are fully supported in Oracle 19c.
- Potential issues: Ensure the name column in v$sysstat contains the exact names ('physical reads', 'db block gets', 'consistent gets') used in this query. Any changes in metric naming conventions (though unlikely) could impact the results.
This script calculates buffer hit ratios and uses the v$sysstat view to determine logical reads, physical writes, and other relevant metrics.
Both queries use the v$sysstat 1) view and 2) look at physical reads as a percentage of consistent_gets plus db_block_gets, but do this in different ways.
In this example, the second query will run faster than the first query, because it joins the V$SYSSTAT table against itself.
Both queries use the V$SYSSTAT view and look at physical reads as a percentage of consistent_gets plus db_block_gets, but do this in different ways. It is common to see identical results come from different coding techniques. Note that this is the accumulated buffer hit ratio since database start time, so it does not indicate the current hit ratio. In this example, the second query runs faster than the first query, because it joins the V$SYSSTAT table against itself.
The next lesson looks at a technique to easily apply what we've learned about query performance, and create an automated alert monitor.