About
## The problem it solves
Modern applications generate complex queries, and when the database slows down, companies lose revenue. Traditionally, identifying bottlenecks and optimizing PostgreSQL databases requires senior Database Administrators (DBAs) spending hours reading cryptic EXPLAIN ANALYZE logs.
While AI (LLMs) can solve this instantly, feeding production SQL queries to third-party AI APIs is a massive security risk. Hardcoded literals often contain sensitive Customer Data, PII, and financial information. Sending this to an AI model violates GDPR, HIPAA, and PCI-DSS compliance.
PrivDB Optimizer bridges this gap. It is an autonomous, privacy-first AI Database Administrator that optimizes workloads in real-time without ever exposing sensitive data.
💡 What People Can Use It For
Instant Query Debugging: Developers can paste a slow query and instantly get a visual Graph Neural Network (GNN) tree showing exactly which node (e.g., Sequential Scan, Hash Join) is causing the bottleneck. Autonomous Optimization: Instead of guessing which index to create, the AI recommends the most mathematically sound strategies (e.g., Composite Indexes, Table Partitioning, Query Rewrites). Workload Drift Detection: Engineering teams can use it to continuously monitor database traffic. If the application shifts from a read-heavy workload to a write-heavy workload, the Reinforcement Learning (RL) engine automatically flags the drift and adapts the indexing strategy. Safe Copilot Assistance: DBAs can chat with the PrivDB Copilot in natural language (e.g., "Why is the orders table slow today?") knowing the AI is only receiving anonymized metadata and live row counts, not real customer data. 🛡️ How It Makes Existing Tasks Easier & Safer Uncompromising Security (Zero-Trust Gateway): It makes AI adoption 100% safe. Before a query is sent to the AI, our Python-based AST parser permanently masks PII (emails, credit cards, SSNs) and hashes all string/numeric literals. The AI only sees structure, never data. Risk-Free Deployments (Sandbox Simulator): Optimizing databases is risky; a bad index can slow down write speeds. PrivDB makes this easier and risk-free by simulating the recommendation in a mathematical sandbox. It calculates the exact execution time reduction versus the storage/write penalty before generating the final migration and rollback SQL scripts. Multi-Agent Consensus: Instead of relying on a single AI hallucination, it uses a multi-agent debate (Optimizer Agent vs. Conservative DBA Agent) to ensure every recommendation balances performance gains with infrastructure costs.
## Challenges we ran into
🚧 Challenges We Ran Into
Building an autonomous, privacy-first database optimizer required connecting deep database internals with AI agents, which brought several complex challenges:
- The Privacy vs. Context Tradeoff
The Hurdle: To ensure zero data leakage, our Privacy Gateway replaces all literals in a query with ? (e.g., WHERE status = 'ACTIVE' becomes WHERE COL_1 = '?'). However, masking this data meant the AI lost crucial context about cardinality and selectivity, resulting in poor index recommendations. The Solution: We engineered a statistical metadata injector. Before calling the LLM, the backend securely queries PostgreSQL's pg_stat_user_tables and pg_class to extract structural metadata (like live row counts, average row sizes, and table sizes). We fed this mathematical metadata to the AI instead of raw data. The AI regained its deep analytical capabilities without ever seeing a single real record.
- Parsing Hierarchical PostgreSQL Plans for GNNs
The Hurdle: Feeding a query's execution plan into our Graph Neural Network (GNN) required converting PostgreSQL's deeply nested, highly complex EXPLAIN (FORMAT JSON) output into a mathematical graph. Initially, the varying node types and nested children caused parsing failures and infinite recursion loops. The Solution: We built a robust recursive Python parser (PostgresPlanParser) that traverses the JSON tree and normalizes it into a directed graph using networkx. We mapped PostgreSQL metrics (Startup Cost, Total Cost, Plan Rows) into numerical node features, allowing our GNN to successfully score and flag the exact "Critical" bottlenecks in red on the React frontend.
- Handling Destructive SQL and Type Errors
The Hurdle: When testing the Query Analyzer, we noticed that if a user submitted a query with a schema mismatch (e.g., comparing a UUID column to an Integer), PostgreSQL threw strict type errors. Initially, this caused unhandled HTTP 500 crashes in our FastAPI backend, breaking the user experience. The Solution: Instead of letting the API crash, we embraced the errors. We implemented a graceful exception handler in the AnalysisService that catches PostgreSQL engine errors (like syntax or type mismatches) and routes them into our AI's "Rewrite Suggestions" engine. Now, the UI elegantly handles the crash, highlights it as a "Bad Query Pattern," and provides the user with the exact Postgres HINT to fix their code.
- Eliminating "Fake Data" for a Real-Time Dashboard
The Hurdle: Hackathon dashboards often rely on hardcoded dummy data, which reduces credibility. We wanted our Overview Dashboard to reflect 100% real-time metrics, but building a full time-series analytics backend in a limited time was challenging. The Solution: We wired the React frontend directly to the live PostgreSQL query_logs via the API. For the "Query Performance Trend" charts, we wrote dynamic JavaScript generators that calculate the last 7 days relative to the live system clock. This ensured the dashboard dynamically reacts to every new query analyzed, guaranteeing an authentic, real-time experience for the judges.
Screenshots
Team
From the public Devfolio project page. Votes, swipes and the judge score are hackfeed's own.










