{"slug": "teaching-an-ai-to-read-a-relational-database-including-oracle-apex", "title": "Teaching an AI to read a relational database — including Oracle APEX", "summary": "A developer built Legacy SQL Architect MCP, an MCP server that connects AI assistants like Claude directly to PostgreSQL, SQL Server, or Oracle databases in read-only mode, enabling autonomous schema inspection, data sampling, and impact analysis. The latest release adds support for Oracle APEX, with six tools that analyze performance, debug logs, configuration anti-patterns, and SQL runtime statistics by querying APEX dictionary views.", "body_md": "A few months back I started building a tool to solve a problem that kept\n\nannoying me: when you want an AI assistant to help with an old database, you end up as a human clipboard — copying schema, pasting stored procedures, describing foreign keys by hand. The AI never actually *sees* the database.\n\nSo I built **Legacy SQL Architect MCP** — an [MCP](https://modelcontextprotocol.io) server that connects Claude (or any MCP-compatible client) directly to your PostgreSQL, SQL Server, or Oracle database, in strict **read-only** mode. The AI inspects the real thing instead of guessing from what you paste.\n\n## The core idea\n\nOnce connected, the assistant can use a set of tools to explore the database on its own:\n\n| Tool | What it does |\n\n|------|--------------|\n\n| `inspect_schema`\n\n| Tables, columns, types, primary & foreign keys |\n\n| `data_sampler`\n\n| Sample rows, with automatic masking of sensitive columns |\n\n| `get_procedure_source`\n\n| Full source of stored procedures and functions |\n\n| `query_plan_expert`\n\n| Execution plan analysis, full-scan detection |\n\n| `dependency_graph`\n\n| FK chains, trigger → procedure call chains, view deps |\n\n| `generate_mermaid_erd`\n\n| An ER diagram in Mermaid |\n\n| `generate_documentation`\n\n| Complete Markdown docs for the whole schema |\n\n| `find_impact`\n\n| Everything that depends on a given table |\n\n| `generate_java_dao`\n\n| Ready-to-compile Java Entity + Repository classes |\n\nSo you can say things like:\n\n\"Inspect the schema, sample the orders table, read the procedures that touch it, and tell me what would break if I rename`order_status`\n\n.\"\n\n…and the assistant actually goes and looks, then answers with references to real objects. Read-only by design — it physically cannot INSERT, UPDATE, or DELETE.\n\n## The new part: Oracle APEX\n\nThis is the release I want to talk about, and I'll be honest about how it came to be.\n\n**I'm not an APEX developer.** I've never shipped a production APEX app. But APEX performance problems are notoriously hard to see, and it turns out Oracle exposes a *lot* about an APEX application through its own dictionary views —\n\n`APEX_APPLICATIONS`\n\n,`APEX_APPLICATION_PAGE_REGIONS`\n\n,`APEX_APPLICATION_LOVS`\n\n, `APEX_WORKSPACE_ACTIVITY_LOG`\n\n, `APEX_DEBUG_MESSAGES`\n\n, and friends. The answer to \"why is this page slow?\" is often sitting right there.\n\nSo I studied those views and turned them into six tools that hand that insight to the AI in a form it can reason about. Every one was verified against a **live APEX 26.1 instance** before shipping.\n\n### `inspect_apex_performance`\n\nAn overview of an application: pages, regions with SQL, LOVs, validations, processes — plus the **slowest pages** by real user activity, and a list of recommendations (slow pages, `SELECT *`\n\nregions, LOVs with no `WHERE`\n\nclause, unconditional processes, …).\n\n\"Run inspect_apex_performance on app 102 and show me the 5 slowest pages and why.\"\n\n### `get_apex_source`\n\nThe APEX counterpart to `get_procedure_source`\n\n: it extracts the embedded code across 12 component types (regions, processes, computations, validations, items, branches, dynamic actions, LOVs, authorizations, …). It introspects each view's columns first, so it tolerates dictionary drift between APEX versions.\n\n\"Get the source of every SQL region on page 3 and summarize what they query.\"\n\n### `inspect_apex_debug`\n\nReads `APEX_DEBUG_MESSAGES`\n\n, reconstructs page views by grouping on the page-view id, finds the slowest ones, and drills into the individual steps — so you can see *where inside a page render* the time actually went.\n\n\"Which page views in the last 2 days were slowest, and what step dominated?\"\n\n### `apex_config_audit`\n\nA static anti-pattern audit — no runtime data needed:\n\n`COUNT(*)`\n\n(\"row N of Z\")\n\n\"Audit app 102 for configuration anti-patterns.\"\n\n### `apex_sql_runtime_stats`\n\nCorrelates the app to its real runtime cost by reading `V$SQL`\n\nfor the app's parsing schema — buffer gets, elapsed time, executions — and flags the hot SQL.\n\n\"What's the most expensive SQL this app has actually run? Order by buffer gets per execution.\"\n\n### `apex_explain_batch`\n\nRuns `EXPLAIN PLAN`\n\nacross an app's SQL regions, SQL LOVs, and Exists-type validations at once, then flags the red lines: `TABLE ACCESS FULL`\n\n,\n\n`MERGE JOIN CARTESIAN`\n\n, `INDEX FULL SCAN`\n\n. (It handles APEX `&SUBSTITUTION.`\n\ntokens by binding them, so the plans actually parse.)\n\n\"Explain-plan all the SQL in app 102 and list anything doing a full scan or a Cartesian join.\"\n\n## None of this is magic\n\nIt's all sitting in Oracle's own dictionary. What the tool does is connect the dots and hand them to the AI in a form it can reason about — grounded in your actual application, not a generic \"best practices\" lecture.\n\n## An honest ask\n\nBecause I'm *not* an APEX expert, I'd genuinely value review from people who are. Am I reading the right views? Is there a metric you always check first that I'm ignoring? Did I get something wrong? You know this platform far better than I do.\n\nIt's open source and free (Apache 2.0), with native installers for Windows and Linux (deb + rpm) that bundle their own Java runtime — no JDK needed.\n\n**GitHub:** [https://github.com/tabforgeai/legacy-sql-architect-mcp](https://github.com/tabforgeai/legacy-sql-architect-mcp)\n\nIf you try it against a real APEX app, I'd love to hear what it found — or where it fell short.", "url": "https://wpnews.pro/news/teaching-an-ai-to-read-a-relational-database-including-oracle-apex", "canonical_source": "https://dev.to/java_freepascal_dev/teaching-an-ai-to-read-a-relational-database-including-oracle-apex-4c5p", "published_at": "2026-07-22 07:49:26+00:00", "updated_at": "2026-07-22 08:01:48.258558+00:00", "lang": "en", "topics": ["artificial-intelligence", "developer-tools", "ai-agents", "ai-infrastructure"], "entities": ["Claude", "Oracle", "PostgreSQL", "SQL Server", "Legacy SQL Architect MCP"], "alternates": {"html": "https://wpnews.pro/news/teaching-an-ai-to-read-a-relational-database-including-oracle-apex", "markdown": "https://wpnews.pro/news/teaching-an-ai-to-read-a-relational-database-including-oracle-apex.md", "text": "https://wpnews.pro/news/teaching-an-ai-to-read-a-relational-database-including-oracle-apex.txt", "jsonld": "https://wpnews.pro/news/teaching-an-ai-to-read-a-relational-database-including-oracle-apex.jsonld"}}