Skip to content

OPA-PA scripts and dashboards: how to write your own

OPA-PA shows nothing it does not get from scripts. Every item in the catalog — a table, a chart, a dashboard, an action such as Kill session, the drill-down from one to another — is a SQL file with a short YAML header, or a YAML file for a dashboard. You can change the shipped scripts and write your own with any text editor; nothing needs to be compiled.

New to OPA-PA? Start with Getting started. This guide is for users who write scripts. The complete reference is metadata-format.md (in English, in this folder); this guide covers everything you need day to day, with examples.

What Where
Your scripts for an engine scripts/<engine> in OPA-PA’s settings folder: scripts/oracle, scripts/postgresql
Settings folder Windows %APPDATA%\OPA · macOS ~/Library/Application Support/OPA · Linux ~/.config/opa
Read-only copy of the shipped scripts shipped-scripts/<engine> in the same folder (Help → Open shipped scripts)
This documentation docs in the same folder (Help → User guide)

Help → About OPA-PA shows the exact folders.

  • Your script replaces a shipped one with the same id. To change a shipped script, right-click it in the catalog and choose Edit a copy: OPA-PA copies it (with all its variants) into your folder and opens the folder. Delete your copy to get the shipped one back. When an OPA-PA update brings a newer version of a script you have overridden, the catalog warns you.
  • OPA-PA reloads your folder when files change. Open views keep the old definition until you reopen or refresh them.
  • A broken script never breaks the others. Its problems are listed in the Diagnostics panel with file and line.
  • The scripts of one folder belong to one engine. Write Oracle SQL in scripts/oracle, PostgreSQL SQL in scripts/postgresql.
  • Subfolders are allowed: they become catalog folders unless the header says category.

Save this as scripts/oracle/my/hello.sql:

select sysdate now, user from dual

It appears in the catalog as Hello in the folder my, and runs as a table. Its id is my.hello (the path, with / replaced by .). A bind such as :owner in a script without a header becomes a text field above the result.

A header is a comment at the very beginning of the file, between /*--- and ---*/. Its content is YAML. The file stays valid SQL.

/*---
id: my.big_tables
title: Biggest Tables
category: My scripts
description: Tables of a schema by size.
inputs:
- { name: owner, label: Owner, default: SCOTT }
- { name: top_n, type: integer, default: 20, label: Top N }
columns:
mb: { label: "Size, MB", format: "#,##0.0" }
---*/
select segment_name table_name, round(sum(bytes) / 1024 / 1024, 1) mb
from dba_segments
where owner = :owner and segment_type like 'TABLE%'
group by segment_name
order by mb desc
fetch first :top_n rows only

Main fields:

Field Meaning
id Unique name: lowercase letters, digits, _ . -. Default: from the file path.
title Name in the catalog and on the tab. Default: from the file name.
category Catalog folder, / separates levels: SQL/Plan Management. Default: the subfolder.
description Tooltip and help text.
inputs Bind variables shown above the result (§4).
ranges Two time inputs shown as one period control (§5).
columns Labels, formats, units and meanings of result columns (§6).
display How to show the result: table, tree, chart, text, document (§7).
refresh Automatic refresh (§8).
navigation Drill-down links and ranking (§9).
steps Several statements in one script (§10).
kind, safety, confirm, transaction Actions that change something (§11).
requires, unless Database version, licences, capabilities (§12).
timeout, maxRows Per-statement timeout (30s, 5m) and row cap for this script.
version Your own revision number of the script (used for the “newer version” warning).

Durations are written with a unit: 500ms, 5s, 1m, 2h, 7d.

Inputs are the script’s bind variables. Values are always bound, never pasted into the SQL text, so they cannot change the statement.

inputs:
- name: sql_id # the bind :sql_id
semantic: oracle.sql.id # its meaning (lets drill-down fill it, §9)
type: string # string | integer | number | date | timestamp | boolean | enum
label: SQL ID
- name: mode
type: enum
choices: [ELAPSED, CPU, IO]
default: ELAPSED
- name: con_id
semantic: oracle.container.id
type: integer
required: false # may be empty (NULL)
showWhen: { capabilities: [cdb_root] } # only where the connection has it (§12)
  • The view opens and runs at once with the values it has. Change a value and press Enter (or Run) to run again.
  • An input is required unless it has a default or says required: false. When a required input has no value, the view waits and says which input is missing.
  • semantic gives the input a meaning, so that it can be filled from a row you double-clicked or from a dashboard selection. Three cases:
    • semantic and no default: the value must come from what you clicked (e.g. the SQL id of SQL details). Such a script is offered in the drill-down menu only when that value is available.
    • semantic and a default (or required: false): taken from the context when there is one, else the default (e.g. a time period, an optional wait class).
    • no semantic: only the default or what you type (e.g. Top N).
  • fromContext: false keeps the default even when the context has a value (e.g. a 7-day history window that should not shrink to a 5-minute dashboard selection).
  • A bind may appear several times; all occurrences are the same value.
  • Only :name is a bind (a letter after the colon). :=, ::text (PostgreSQL casts), and text inside quotes or comments are not binds. :1 and ? are not allowed.
  • PostgreSQL: if the query does not tell the type of a bind, cast it: :name::text is null, :t_from::timestamp.

Defaults of date and timestamp inputs may be time expressions:

Expression Meaning
now the database’s current time
now-15m, now-2h, now-7d before now (s m h d w)
now/d, now/h rounded down: start of today, of this hour (w: Monday)
now-1d/d 00:00 yesterday
2026-10-29 10:00 a fixed time
  • now is the database clock, not your computer’s: time zones and clock differences do not matter.
  • A relative value stays relative: every run (and every auto-refresh) recomputes it, so “the last 15 minutes” moves with time. When you pick a date in the picker, it becomes fixed.
  • type: date is a date with time of day (Oracle DATE); type: timestamp a TIMESTAMP. precision: day shows only a date picker.

A range shows two time inputs as one period control with presets:

inputs:
- { name: t_from, semantic: perf.time.range.start, type: timestamp, default: now-15m, label: From }
- { name: t_to, semantic: perf.time.range.end, type: timestamp, default: now, label: To }
ranges:
- { from: t_from, to: t_to, label: Period, presets: [5m, 15m, 1h, 1d] }

A preset sets from = now-<preset> and to = now. The script does not run while From is not before To.

Use the semantic keys perf.time.range.start / perf.time.range.end for a period: then a period selected on a chart (§7.3) fills From and To of the script you open from it.

columns:
sql_id: oracle.sql.id # short form: just the meaning
elapsed_s:
label: "Elapsed, s"
format: "#,##0.00" # number pattern
unit: s # s | ms | us | bytes | percent | count: readable values (1.2 GB, 3 min)
width: 90
hidden: true # not shown, still usable for drill-down
key: true # identifies the row: the selection stays on it after a refresh
sensitive: true # never sent to an AI provider unless the data policy is Full (§15)

Column names are matched without regard to case. Semantic keys (oracle.sql.id, oracle.session.sid, postgresql.backend.pid…) are what makes drill-down work: a column with the key oracle.sql.id can fill any input with that key. Use the keys of the shipped scripts (open them in shipped-scripts to see which ones). Common columns (sql_id, inst_id, sid, serial# on Oracle; pid, queryid on PostgreSQL) get their keys automatically from the pack, even in a script without a header.

A text value of the form below is drawn as a small graphic in the table. No header is needed: the SQL decides.

Value Drawn as
bar(42) or bar(42,100) a bar behind the number (42 of 100; without a maximum, relative to the largest in the column)
stacked-bar(CPU=12;User I/O=30) or stacked-bar({"CPU":12,"User I/O":30}) one bar split into coloured parts
sparkline(3,5,,8) or sparkline([3,5,null,8]) a tiny line chart; an empty item is a gap

Use . as the decimal separator (in Oracle: to_char(v, 'TM9', 'NLS_NUMERIC_CHARACTERS=''.,'''), or json_arrayagg). Optional styling:

columns:
activity:
width: 160
cell: { palette: wait-classes, colors: { CPU: "#3CB043" }, scale: column } # scale: row = every bar full width
trend:
cell: { style: area, color: "#1F6FEB" } # sparkline style: line | area | bars
display:
renderer: table # table | record | chart | text | document
alternatives: [record] # other views offered in the view's switcher

Switching between table, record and chart never runs the query again.

The default. Columns can be sorted, resized, moved and hidden; cells and rows can be copied as TSV, CSV, JSON, SQL INSERT, SQL select … union all or an IN list (right-click, or Ctrl+C / Ctrl+Shift+C with the header). Record shows the selected row as name/value pairs.

Rows that form a hierarchy — blocking chains, plan lines, object dependencies — can be shown as a tree: rows with children get a ▾ / ▸ toggle and are indented.

display:
tree: "(blocking_instance, blocking_session) > (inst_id, sid)"

The text before > names the columns that hold the parent’s key; after >, the columns that are the row’s own key, in the same order. One column needs no parentheses: tree: "parent_id > id". The long form adds options:

display:
tree:
key: [inst_id, sid]
parent: [blocking_instance, blocking_session]
column: chain # where the toggles are (default: the first visible column)
expanded: all # all (default) | none | 1, 2… levels open at first
columns:
blocking_instance: { hidden: true }
blocking_session: { hidden: true }
  • A row whose parent columns are empty (NULL), or point to a row that is not in the result, is a top-level row.
  • Children are shown in the order of the result: order the query (Oracle order siblings by).
  • Numbers are compared by value, so an INTEGER key matches a NUMBER parent.
  • If the same node can appear twice (a session waiting on two blockers), give each row its own key, e.g. its path from the top: tree: "parent_path > path".
  • Collapsed rows stay collapsed when the view refreshes. Right-click → Expand all / Collapse all; Alt+Right / Alt+Left on the selected row.

Oracle example: a blocking tree.

/*---
id: my.blockers
title: Blockers
columns:
blocking_instance: { hidden: true }
blocking_session: { hidden: true }
display:
tree: "(blocking_instance, blocking_session) > (inst_id, sid)"
---*/
select inst_id || ':' || sid session_, inst_id, sid, serial#, username, event,
case when level > 1 then blocking_instance end blocking_instance,
case when level > 1 then blocking_session end blocking_session
from gv$session s
start with blocking_session is null
and exists (select 1 from gv$session w where w.blocking_instance = s.inst_id and w.blocking_session = s.sid)
connect by nocycle prior inst_id = blocking_instance and prior sid = blocking_session
order siblings by inst_id, sid
display:
renderer: chart
alternatives: [table]
chart:
type: stacked-area # line | area | stacked-area | bar | stacked-bar
x: sample_time # a time or category column
series: wait_class # long format: one row per (x, series) with one value column...
value: aas
# values: [reads, writes] # ...or wide format: several value columns
yLabel: Average active sessions
palette: wait-classes # colours from the pack, or colors: { CPU: "#3CB043" }
xRange: { from: t_from, to: t_to } # the x-axis spans the inputs' period
fill: { step: 1m, missing: zero } # regular time grid: empty minutes are 0 (gap: break the line)
selection:
range: { from: perf.time.range.start, to: perf.time.range.end } # drag selects a period
click: bucket # point (default) | bucket: a click selects one step as a period | none
bucket: 1m
default: { from: now-5m, to: now } # initial selection
follow: true # the selection moves with time on refresh
  • Click a point or a bar segment: its row’s values (time, series, other columns with keys) become the selection.
  • Drag along a time axis: the period becomes the selection. Right-click inside the period lists the scripts that take a period; they open with From/To of the selection. Esc clears the selection.
  • Follow (toolbar toggle): the selected period is kept relative to now, so on each refresh it moves and the dependent views re-run.
  • Use fill for sparse data (sampled activity on a quiet database), so idle minutes drop to zero instead of joining the points around them.
display:
renderer: text
text: { format: sql } # optional: also a "Formatted" tab for SQL text

A one-column result shown as monospaced lines, e.g. dbms_xplan output.

display:
renderer: document
document: { column: report, mime: text/html, open: external }

The first row’s CLOB/BLOB column is opened in your browser (e.g. an Active SQL Monitor report); Save as… is always available.

refresh:
interval: 15s # when the view opens; without it, manual refresh only
choices: [5s, 15s, 1m, 5m] # offered in the view's refresh selector (Off is always there)
minInterval: 5s

A refresh is skipped while the previous run is still going. Views in hidden tabs do not refresh; when shown again, they refresh once if their data is old. Your choice of interval is remembered per script.

You do not wire scripts together. When you double-click a row (or right-click it, or click a chart), OPA-PA looks at the semantic keys of the row and offers every script whose inputs they can fill:

  • every input with a semantic and no default must get a value; and
  • at least one input must get its value from the row itself (not only from the dashboard or connection).

Double-click opens the best match; the context menu lists all of them, grouped by category, with those that miss a value shown disabled. Ctrl+double-click opens in a new window.

To steer it:

navigation:
priority: 100 # on a target: ranks it higher among the matches
hidden: true # never offered automatically, only through links
links: # on a source: explicit targets
- target: sql.details
label: SQL details
default: true # the double-click target
- target: my.plan
map: { sql_id: oracle.sql.id } # fill the target's input sql_id from this key

Values travel along a chain: from Top SQL to SQL details to the plan, the instance, container and period stay with you.

Without steps, the whole file is one statement. Do not end it with ; unless it is a PL/SQL block; a trailing / line (Oracle) is removed. For several statements, declare steps and separate them with --@step <name> lines:

/*---
id: my.plan_with_stats
title: Plan with Row Source Statistics
inputs:
- { name: sql_id, semantic: oracle.sql.id, label: SQL ID }
steps:
- { name: setup, type: session, output: none }
- { name: plan, type: sql, output: result, label: Plan }
display: { renderer: text }
---*/
--@step setup
alter session set statistics_level = all
--@step plan
select plan_table_output from table(dbms_xplan.display_cursor(:sql_id, null, 'ALLSTATS LAST'))
  • All steps run in order on one session. A failing step stops the script (unless continueOnError: true).
  • type: sql, block (Oracle PL/SQL begin … end;; PostgreSQL DO), session (session settings).
  • output: result (shown, one tab per result; display: { layout: stacked } shows them one under another), messages, or none.
  • serverOutput: true shows DBMS_OUTPUT (Oracle) or notices (PostgreSQL).
  • OPA-PA never splits on ;: only the marker lines separate statements.

A script that changes something is an action:

/*---
id: my.kill
title: Kill Session
category: Sessions
kind: action
safety: dangerous # read | write | dangerous
transaction: none # rollback (default) | commit | none
confirm: "Kill session {sid},{serial} on instance {inst_id}?"
inputs:
- { name: inst_id, semantic: oracle.instance.number, type: integer }
- { name: sid, semantic: oracle.session.sid, type: integer }
- { name: serial, semantic: oracle.session.serial, type: integer }
steps:
- { name: kill, type: block, output: messages }
---*/
--@step kill
begin
execute immediate 'alter system kill session '''
|| to_char(:sid) || ',' || to_char(:serial) || ',@' || to_char(:inst_id) || ''' immediate';
end;
  • write and dangerous always show a confirmation with the statement and the values; dangerous needs an extra tick. An action is never the double-click default.
  • transaction: queries are always rolled back; an action may commit after its last step, or leave it to the SQL (none).
  • confirm is display text only; {name} shows an input’s value.
  • OPA-PA never builds SQL from values. If your block builds dynamic SQL itself (as above), use typed inputs (integer) and convert them explicitly.
  • Database privileges are the real limit: OPA-PA’s safety levels protect you from mistakes, not from permissions.
requires:
version: "12.2" # minimum database version (quote it)
licenses: [diagnostics] # Oracle: diagnostics, tuning
capabilities: [pg_stat_statements]
unless:
licenses: [diagnostics] # not used when this licence is confirmed
  • A script whose requirements are not met is hidden in the catalog (Show unavailable shows it greyed, with the reason), never offered in drill-down and never run.
  • Oracle licences. Diagnostics Pack and Tuning Pack are confirmed per connection in the connection dialog. A script that reads ASH, AWR or SQL Monitor must say requires: { licenses: [...] }; OPA-PA warns when a script uses such a view without it. Without the Diagnostics Pack, OPA-PA’s own session samples stand in for ASH (§16).
  • Capabilities are detected, not confirmed: PostgreSQL extensions (pg_stat_statements, pg_wait_sampling, pg_stat_kcache, pgstattuple), Oracle cdb_root / pdb. showWhen: { capabilities: [...] } on a column or an input shows it only where the database has them.
  • Variants. One script can have several files with the same id, chosen per connection by the file name: top_sql.sql, top_sql@11.2.sql (from version 11.2), top_sql+tuning.sql (with the Tuning Pack), bloat+pgstattuple.sql (where the extension exists). The connection uses the variant with the highest version it meets, then the one with more licences and capabilities. Dashboards and links name the id only.

A dashboard is a .yaml file that arranges views and passes selections between them:

id: my.activity
title: My Activity
category: Dashboards
kind: container
inputs:
- { name: t_from, semantic: perf.time.window.start, type: timestamp, default: now-60m }
- { name: t_to, semantic: perf.time.window.end, type: timestamp, default: now }
ranges:
- { from: t_from, to: t_to, label: Window, presets: [15m, 1h, 6h, 1d] }
refresh:
interval: 15s
choices: [5s, 15s, 1m]
layout:
type: split # split | tabs | grid | view
orientation: vertical # split: vertical | horizontal
ratios: [0.55, 0.45]
children:
- view: ash.activity_by_wait_class
publishSelectionAs: picked # its selection goes to the channel "picked"
- type: tabs
contextFrom: picked # these views get the channel's values
children:
- view: ash.top_sql_for_range
- view: ash.top_sessions_for_range
  • grid takes columns: N and fills rows left to right.
  • The dashboard’s inputs are shown in its own inputs bar and passed to every child by semantic key (the window above fills the chart’s t_from/t_to).
  • A child under contextFrom waits until the channel has a value; a chart’s selection.default gives one at once.
  • Only the views whose values changed run again. The dashboard’s refresh drives the views without contextFrom; the others re-run when their channel changes.
  • A view node may override the child’s display, refresh or fix some inputs.
  • A child that is unavailable on the connection (version, licence) is shown as a placeholder with the reason.
/*---
id: my.awr_report
title: AWR Report (SQL*Plus)
client: sqlplus # sqlplus | sqlcl | psql, or a list: the first one configured is used
safety: read
---*/
@?/rdbms/admin/awrrpt

OPA-PA does not run such a script itself: Run in… opens the client in a terminal, logged on to the current connection, and runs it. The text is used as written, client commands included (set, column, spool, \d). Inputs become the client’s variables: :name and &name in SQL*Plus/SQLcl, :name in psql. Without exit (\q) the client stays open. View → External tools sets where each client is and the folder it starts in (where your own @scripts are).

The AI assistant and OPA-PA’s MCP server can list, describe and run your read-only scripts, like the shipped ones. To control that:

ai: false # keep this script away from the AI (e.g. a large HTML report)
columns:
bind_value: { sensitive: true } # withheld from the AI unless the data policy is Full

Actions are never offered to the AI. A good title, description and input labels help the model choose the right script.

Where the database has no activity history (PostgreSQL), or one that needs a licence (Oracle ASH without the Diagnostics Pack), OPA-PA samples active sessions every second into a local file. Scripts with source: local query these samples with SQLite SQL (Oracle example; the PostgreSQL samples call the column usename):

/*---
id: my.local_top_users
title: Top Users (local samples)
source: local
inputs:
- { name: t_from, semantic: perf.time.range.start, type: timestamp, default: now-15m }
- { name: t_to, semantic: perf.time.range.end, type: timestamp, default: now }
---*/
select username USERNAME, round(1.0 * sum(weight) / (select sum(weight) from session_samples_samples
where sample_time >= :t_from and sample_time < :t_to), 2) AAS
from session_samples
where sample_time >= :t_from and sample_time < :t_to
group by username
order by 2 desc
  • Each sampler table <table> has one row per sampled session, with sample_id, sample_time, weight; <table>_samples has one row per sample taken. Divide by sum(weight) of the samples taken, not by the length of the period.
  • The shipped samplers are session_samples (Oracle gv$session; PostgreSQL pg_stat_activity). Look at them in shipped-scripts to see their columns.
  • Write result column names in upper case, like database scripts.
  • Problems appear in the Diagnostics panel at the bottom, with file, line and column. An error rejects the script; a warning (an unknown field, an unused input) does not.
  • Typical errors: invalid YAML (check indentation; quote text with : or #), an input without a matching bind, --@step markers that do not match steps, an invalid time expression, :1 or ? placeholders, a tree with different numbers of parent and key columns.
  • The SQL button in a view’s toolbar opens its statements in the SQL worksheet with the values filled in, to try changes.
  • Start from a shipped script: Edit a copy, change it, save — the view picks it up when you reopen it.
/*---
id: my.example # unique; default: from the path
title: Example # default: from the file name
category: My/Examples # catalog folder
description: What it shows.
inputs:
- { name: t_from, semantic: perf.time.range.start, type: timestamp, default: now-15m, label: From }
- { name: t_to, semantic: perf.time.range.end, type: timestamp, default: now, label: To }
- { name: top_n, type: integer, default: 20, label: Top N }
ranges:
- { from: t_from, to: t_to, label: Period, presets: [15m, 1h, 1d] }
columns:
sql_id: oracle.sql.id
secs: { label: "Time, s", unit: s, format: "#,##0.0" }
display:
renderer: table # table | record | chart | text | document
alternatives: [chart]
# tree: "parent_id > id"
# chart: { type: bar, x: sql_id, value: secs }
refresh: { interval: 1m, choices: [15s, 1m, 5m] }
# requires: { version: "19", licenses: [diagnostics] }
# kind: action, safety: write, transaction: commit, confirm: "…"
---*/
select ...