Expand description
SQL builders for Phase 4 monitoring / DDL tools.
Ported from pro/.../ToolExecutor.ts + core/commands/sql/{profile,monitoring}.ts.
Constants§
- REPORT_
LIMIT_ DEFAULT - REPORT_
LIMIT_ MAX - Max rows for advisory reports (
suggest_indexes, unused indexes, bloat, missing FKs). - SLOW_
QUERIES_ DEFAULT - SLOW_
QUERIES_ MAX - Max rows for
slow_queries(matches TSMonitoringSQL.slowQueries).
Functions§
- bloat_
report - Approximate table bloat via dead-tuple ratio (not physical page bloat). Documented simplified estimate — avoids heavy pgstattuple / check_postgres SQL.
- blocking_
locks - cache_
hit_ ratio - column_
details - column_
stats - connection_
states - dashboard_
active_ queries - Dashboard: backends for current DB (incl. idle), capped.
- dashboard_
db_ info - Dashboard: database owner + pretty size for
current_database(). - dashboard_
extension_ count - dashboard_
max_ connections - dashboard_
object_ counts - Dashboard: object counts (non-system).
- dashboard_
top_ tables - Dashboard: top tables by total relation size.
- database_
maintenance_ stats - database_
stats - enhance_
sql_ error - Enrich a Postgres error with schema-index hints (qualified ref, did-you-mean).
- find_
missing_ fks_ catalog - Catalog fallback:
*_idcolumns with no FK that name-match another table’s PK. - find_
unused_ indexes - Unused indexes:
idx_scan = 0, excluding PK / UNIQUE / constraint-backed (matches ProDashboardDataunusedIndexes query). - high_
seq_ scan_ tables - Tables with high sequential-scan ratio — primary
suggest_indexesheuristic (ported from Pro dashboardhighSeqScanTables). - index_
usage - is_
safe_ ident - Validate a SQL identifier (table/column name).
- list_
extensions - list_
roles - All roles (ported from core
QueryBuilder.databaseRoles). - map_
stat_ statements_ error - Map tokio-postgres errors from
pg_stat_statementsqueries to actionable guidance. - parse_
ref - Validate
schema.name(or bare name →public) as plain SQL identifiers. - quote_
ident - Double-quote an identifier (idents already validated via
parse_ref). - quote_
ref - regclass_
literal - String literal for
'\"schema\".\"name\"'::regclass. - role_
details - Single-role attributes (
$1= role name). - role_
has_ members - Roles that are members of this role (
$1= role name). - role_
member_ of - Roles this role is a member of (
$1= role name). - role_
table_ privileges - Table privileges granted to a role (
$1= role name). Cap via LIMIT in caller if needed. - running_
queries - server_
settings - slow_
queries - table_
activity - table_
stats - unindexed_
fk_ columns - Foreign-key columns lacking a covering btree index — classic missing-index heuristic.