Skip to main content

Module sql

Module sql 

Source
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 TS MonitoringSQL.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
find_missing_fks_catalog
Catalog fallback: *_id columns with no FK that name-match another table’s PK.
find_unused_indexes
Unused indexes: idx_scan = 0, excluding PK / UNIQUE / constraint-backed (matches Pro DashboardData unusedIndexes query).
high_seq_scan_tables
Tables with high sequential-scan ratio — primary suggest_indexes heuristic (ported from Pro dashboard highSeqScanTables).
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_statements queries 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.