Check the parse ratio and prepared statement cache in Oracle
High parse rates mean Oracle is doing the same optimization work over and over. v$sysstat shows the reuse ratio in one query.
The task
Parsing turns SQL text into an executable cursor. A hard parse (no matching cursor in the shared pool) optimizes the statement from scratch and takes shared pool latches and mutexes while it does. A soft parse finds an existing cursor but still checks syntax, privileges and the session's settings. Executing a cursor the session already holds open costs neither. Applications that paste literal values into SQL instead of using bind variables produce new SQL text for every value, so every execution is a hard parse, and on a busy instance the latch contention slows everyone down.
The snippet
Written for Oracle.
SELECT name, value
FROM v$sysstat
WHERE name IN ('parse count (total)', 'parse count (hard)', 'execute count')
ORDER BY name;
How it works
v$sysstat holds instance-wide counters since startup. Read them as two ratios. Hard parses as a share of total parses should be small; a high share means statements are not being shared, usually because of literals. Total parses as a share of executions shows whether the application keeps cursors open and re-executes them: near 100 percent means it parses before every execution, and with bind variables plus client-side statement caching it falls well below that. If hard parses dominate, the real fix is bind variables in the application. CURSOR_SHARING = FORCE makes Oracle replace literals with binds itself, a workaround with its own plan-stability risks, and a larger shared pool only helps when reusable cursors are being aged out.
Variations
Compute the hard parse percentage directly
SELECT ROUND(100.0 * MAX(CASE WHEN name = 'parse count (hard)' THEN value END)
/ NULLIF(MAX(CASE WHEN name = 'parse count (total)' THEN value END), 0), 2) AS hard_parse_pct,
ROUND(100.0 * MAX(CASE WHEN name = 'parse count (total)' THEN value END)
/ NULLIF(MAX(CASE WHEN name = 'execute count' THEN value END), 0), 2) AS parse_per_exec_pct
FROM v$sysstat
WHERE name IN ('parse count (total)', 'parse count (hard)', 'execute count');
Check session cursor cache effectiveness
SELECT name, value
FROM v$sysstat
WHERE name IN ('session cursor cache hits', 'session cursor cache count');
Questions that come up
What is a healthy hard parse percentage?
A common rule of thumb is a few percent of total parses on a steady OLTP instance; compare against your own baseline rather than a fixed number. Jumps usually come from new literal-heavy application code, DDL or statistics gathering on hot tables (which invalidates the cursors that depend on them), or a shared pool too small to hold the working set of cursors.
Where do prepared statements fit in PostgreSQL and MySQL?
Same idea: prepare once, execute many times. PostgreSQL has no shared plan cache; plans are cached per session, and pg_prepared_statements shows the current session's prepared statements with generic_plans and custom_plans counts (PostgreSQL 14 and later). MySQL counts Com_stmt_prepare and Com_stmt_execute in its global status, and performance_schema.prepared_statements_instances lists the live ones. Literal values pasted into SQL defeat reuse on every engine.
Keep reading
Run these with autocomplete that knows your tables
SQLly is a native SQL workbench for macOS, Windows and Linux. Paste a snippet into a live connection and you get schema-aware IntelliSense, a plan viewer and guards against unsafe edits.