A multi-agent system built with Google's Agent Development Kit (ADK) for comprehensive PostgreSQL database administration, monitoring, and optimization.
This system provides intelligent database administration through specialized agents that can analyze performance, security, maintenance, and schema issues in PostgreSQL databases. Each agent is designed to handle specific aspects of database management, working together to provide comprehensive insights and recommendations.
Watch the demo to see the PostgreSQL DBA Multi-Agent System in action, showcasing performance analysis, security auditing, maintenance monitoring, and schema optimization capabilities.
- Coordinator Agent: Orchestrates multi-agent workflows and coordinates complex database analysis
- Performance Agent: Identifies and analyzes performance bottlenecks, slow queries, and optimization opportunities
- Security Agent: Audits database security, user privileges, and identifies vulnerabilities
- Maintenance Agent: Monitors table maintenance needs, index usage, and database health
- Schema Agent: Analyzes database schema design and suggests improvements
- Synthesis Agent: Combines results from multiple agents into comprehensive reports
- Google Agent Development Kit (ADK): Core agent framework
- MCP Toolbox for PostgreSQL: Database tools and utilities
- PostgreSQL: Target database system
- Python: Primary development language
This guide assumes you have already done the following:
- Python 3.11+ (including uv and your preferred virtual environment tool for managing dependencies e.g. venv)
- PostgreSQL 15+ and the psql client
- Google Cloud credentials (for ADK) - Optional if using Vertex AI
If you plan to use Google Cloud's Vertex AI with your agent, follow these one-time setup steps for local development:
- Install the Google Cloud CLI
- Set up Application Default Credentials (ADC)
- Set your project and enable Vertex AI
gcloud config set project YOUR_PROJECT_ID gcloud services enable aiplatform.googleapis.com
-
Connect to PostgreSQL
psql -h 127.0.0.1 -U postgres
-
Create a new database and user (IAM-based)
-- For IAM-based authentication, CREATE DATABASE toolbox_db; GRANT ALL PRIVILEGES ON DATABASE toolbox_db TO iam_user; ALTER DATABASE toolbox_db OWNER TO iam_user; \q
-
Connect with your new user (IAM authentication)
# Using IAM authentication (no password required) psql -h 127.0.0.1 -U iam_user -d toolbox_db
-
Set up test data (optional)
# Run the test data scripts to populate your database psql -h 127.0.0.1 -U iam_user -d toolbox_db -f sql-test-data/01-schema/create_schema.sql psql -h 127.0.0.1 -U iam_user -d toolbox_db -f sql-test-data/02-data/populate_data.sql
-
Download the latest version of Toolbox
export OS="linux/amd64" # one of linux/amd64, darwin/arm64, darwin/amd64, or windows/amd64 curl -O https://storage.googleapis.com/genai-toolbox/v0.14.0/$OS/toolbox chmod +x toolbox
-
Configure your tools.yaml The project includes a pre-configured
mcp-toolbox-postgres/tools.yaml
file with comprehensive PostgreSQL DBA tools. -
Run the Toolbox server
./toolbox --tools-file "mcp-toolbox-postgres/tools.yaml"
-
Install dependencies
pip install toolbox-core google-adk
-
Configure environment variables
export GOOGLE_API_KEY="your-api-key" export DATABASE_HOST="127.0.0.1" export DATABASE_PORT="5432" export DATABASE_NAME="toolbox_db" export DATABASE_USER="iam_user" # No password needed with IAM authentication
-
Run the DBA Agent
adk web
- Slow Query Detection: Identifies queries with poor performance
- Index Analysis: Finds missing, unused, or redundant indexes
- Blocking Sessions: Detects and analyzes blocking processes
- Cache Hit Ratios: Monitors buffer cache efficiency
- User Privilege Analysis: Reviews user permissions and roles
- Authentication Methods: Audits authentication configurations
- Access Control Review: Identifies security vulnerabilities
- Data Exposure Detection: Finds sensitive data exposure risks
- Table Bloat Analysis: Identifies tables needing VACUUM
- Statistics Monitoring: Tracks outdated table statistics
- Index Maintenance: Suggests index optimization
- Database Size Monitoring: Tracks database growth
- Design Pattern Review: Identifies schema anti-patterns
- Constraint Analysis: Reviews foreign key and constraint design
- Data Type Optimization: Suggests data type improvements
- Normalization Assessment: Evaluates database normalization
# Database Configuration (IAM-based)
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=your_database
DATABASE_USER=your_username
# No password needed with IAM authentication
# ADK Configuration
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json
# Agent Configuration
SPECIALIZED_AGENTS_MODEL=gemini-2.5-flash
COORDINATOR_MODEL=gemini-2.5-flash
TOOLBOX_URL=http://localhost:5000
The MCP toolbox is configured via mcp-toolbox-postgres/tools.yaml
. This file contains:
- Database connection settings
- Available tools and their parameters
- Tool descriptions and usage instructions
postgres-agent/
βββ postgres-dba-agent/ # Main agent system
β βββ agent.py # Main coordinator agent
β βββ config.py # Configuration settings
β βββ subagents/ # Specialized agents
β β βββ performance_agent.py
β β βββ security_agent.py
β β βββ maintenance_agent.py
β β βββ ...
β βββ utils/ # Utility functions
βββ mcp-toolbox-postgres/ # MCP toolbox configuration
β βββ tools.yaml # Tool definitions
βββ sql-test-data/ # Test data and scenarios
β βββ 01-schema/ # Schema creation scripts
β βββ 02-data/ # Data population scripts
β βββ 03-performance-issues/ # Performance test scenarios
β βββ 04-security-issues/ # Security test scenarios
β βββ 05-maintenance-issues/ # Maintenance test scenarios
β βββ 99-cleanup/ # Cleanup scripts
βββ README.md # This file
The project includes comprehensive test data to validate agent capabilities:
- Schema Creation: Creates realistic e-commerce and analytics schemas
- Data Population: Generates test data with various patterns
- Performance Issues: Introduces intentional performance problems
- Security Issues: Creates security vulnerabilities for testing
- Maintenance Issues: Generates maintenance scenarios
# Set up test environment
psql -h localhost -U postgres -d test_database -f sql-test-data/01-schema/create_schema.sql
psql -h localhost -U postgres -d test_database -f sql-test-data/02-data/populate_data.sql
# Run performance tests
psql -h localhost -U postgres -d test_database -f sql-test-data/03-performance-issues/create_performance_issues.sql
# Run security tests
psql -h localhost -U postgres -d test_database -f sql-test-data/04-security-issues/create_security_issues.sql
# Run maintenance tests
psql -h localhost -U postgres -d test_database -f sql-test-data/05-maintenance-issues/create_maintenance_issues.sql
# Clean up after testing
psql -h localhost -U postgres -d test_database -f sql-test-data/99-cleanup/cleanup_all.sql
For deploying the ADK-based agents, follow the official Google ADK deployment guide:
Deploy to Container-friendly Infrastructure
This covers deployment options including:
- Agent Engine in Vertex AI
- Cloud Run
- Google Kubernetes Engine (GKE)
- Other container-friendly infrastructure
For deploying the MCP toolbox service, follow the official MCP Toolbox deployment guide:
Deploy MCP Toolbox to Cloud Run
This covers:
- Cloud Run deployment
- Kubernetes deployment
- Docker Compose deployment
- Configuration and secrets management
- Scenario Testing: Use DBA_AGENT_TEST_SCENARIOS.md for comprehensive validation
π Quick Setup: For immediate help with "Function not found in tools_dict" errors, see QUICK_SETUP.md
-
Toolbox Connection Errors
- Verify toolbox is running on correct port (default: 5000)
- Check
TOOLBOX_URL
in configuration - Ensure tools.yaml file is properly formatted
- Review toolbox logs for errors
- Cold Start Issues: Use automatic retry mechanism (built-in)
-
Tool Execution Errors
- Verify database credentials in tools.yaml (IAM-based authentication)
- Check database permissions for iam_user
- Ensure database exists and is accessible
- Verify IAM roles and permissions are properly configured
-
Google Cloud Credentials
- Verify
GOOGLE_API_KEY
is set correctly - For Vertex AI, ensure Application Default Credentials are configured
- Check project permissions and API enablement
- Verify
-
Model Access Issues
- Verify model access permissions
- Check quota limits
- Review agent logs for specific errors
The system provides comprehensive logging at multiple levels:
- Agent execution logs
- Tool execution logs
- Database query logs
- Error and warning logs
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
- Google Agent Development Kit (ADK)
- MCP Toolbox for PostgreSQL
- PostgreSQL community
- Google Cloud Platform
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review the official ADK and MCP documentation
Note: This system is designed for PostgreSQL databases. Ensure you have appropriate permissions and follow security best practices when deploying in production environments.