Skip to content

Latest commit

Β 

History

History
204 lines (155 loc) Β· 4.75 KB

File metadata and controls

204 lines (155 loc) Β· 4.75 KB

AgentShip - Database Storage Setup

This directory contains scripts for setting up PostgreSQL database storage for AI Agents session management.

πŸ“ Files

  • setup_local_postgres.sh - Local PostgreSQL setup script
  • setup_heroku_postgres.sh - Heroku PostgreSQL setup script
  • verify_db_setup.py - Database verification script
  • POSTGRES_SETUP.md - Detailed setup documentation
  • README.md - This file

πŸš€ Quick Setup

Local Development

# Set up local PostgreSQL database
./setup_local_postgres.sh

Heroku Production

# Set up Heroku PostgreSQL addon
./setup_heroku_postgres.sh

πŸ—„οΈ Database Configuration

Local Database

  • Database Name: ai_agents_session_store
  • Username: ai_agents_user
  • Password: ai_agents_password
  • Host: localhost
  • Port: 5432

Heroku Database

  • Addon Name: ai-agents-session-store
  • Plan: essential-0 ($5/month)
  • Database Name: Auto-generated by Heroku

πŸ”§ Scripts Overview

setup_local_postgres.sh

Sets up PostgreSQL on your local machine:

  • Checks if PostgreSQL is installed and running
  • Creates database and user if they don't exist
  • Updates .env file with SESSION_STORE_URI
  • Handles macOS Homebrew PostgreSQL setup

Usage:

# Basic setup
./setup_local_postgres.sh

# Custom configuration
DB_NAME=my_db DB_USER=my_user ./setup_local_postgres.sh

setup_heroku_postgres.sh

Sets up PostgreSQL addon on Heroku:

  • Creates Heroku PostgreSQL addon
  • Sets SESSION_STORE_URI environment variable
  • Handles addon creation and configuration

Usage:

# Basic setup
./setup_heroku_postgres.sh

# Custom app name
APP_NAME=my-app ./setup_heroku_postgres.sh

verify_db_setup.py

Verifies database setup and connectivity:

  • Tests database connection
  • Verifies user permissions
  • Tests table creation capabilities

Usage:

# Verify local setup
SESSION_STORE_URI="postgresql://ai_agents_user:ai_agents_password@localhost:5432/ai_agents_session_store" python verify_db_setup.py

# Verify Heroku setup
heroku run python verify_db_setup.py --app ai-agents-alpha

πŸ” Troubleshooting

Local PostgreSQL Issues

PostgreSQL Not Running

# macOS with Homebrew
brew services start postgresql

# Check status
brew services list | grep postgresql

Permission Denied

# Create default database for your user
createdb $(whoami)

# Or connect as postgres user
psql -U postgres

Database Already Exists

The scripts check for existing databases and users before creating them, so it's safe to run multiple times.

Heroku PostgreSQL Issues

Addon Creation Failed

# Check Heroku CLI login
heroku auth:whoami

# Check app access
heroku apps:info --app ai-agents-alpha

Environment Variable Not Set

# Check SESSION_STORE_URI
heroku config:get SESSION_STORE_URI --app ai-agents-alpha

# Set manually if needed
heroku config:set SESSION_STORE_URI="your-connection-string" --app ai-agents-alpha

πŸ“Š Database Queries

Check Tables

-- List all tables
\dt

-- Or using SQL
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

Check Sessions

-- View sessions table
SELECT * FROM sessions LIMIT 10;

-- Check recent sessions
SELECT * FROM sessions ORDER BY create_time DESC LIMIT 5;

Check Database Size

-- Local PostgreSQL
SELECT pg_size_pretty(pg_database_size('ai_agents_session_store'));

-- Heroku PostgreSQL
SELECT pg_size_pretty(pg_database_size(current_database()));

πŸ”„ Environment Variables

Required for Database Sessions

  • SESSION_STORE_URI - PostgreSQL connection string

Optional for Local Setup

  • DB_NAME - Database name (default: ai_agents_session_store)
  • DB_USER - Database username (default: ai_agents_user)
  • DB_PASSWORD - Database password (default: ai_agents_password)
  • DB_HOST - Database host (default: localhost)
  • DB_PORT - Database port (default: 5432)

Optional for Heroku Setup

  • APP_NAME - Heroku app name (default: ai-agents-alpha)
  • POSTGRES_PLAN - PostgreSQL plan (default: essential-0)

πŸ“ˆ Monitoring

Local Database

# Check PostgreSQL status
brew services list | grep postgresql

# View PostgreSQL logs
tail -f /usr/local/var/log/postgres.log

Heroku Database

# Check addon status
heroku addons:info heroku-postgresql --app ai-agents-alpha

# View database metrics
heroku pg:info --app ai-agents-alpha

πŸ”— Related Documentation