PostgreSQL Setup for AegisLM
🐳 Option 1: Docker (Easiest)
Step 1: Install Docker Desktop
- Download Docker Desktop from https://www.docker.com/products/docker-desktop/
- Install and start Docker Desktop
- Make sure Docker is running (check system tray)
Step 2: Start PostgreSQL
cd d:\Projects\ALM\backend
docker-compose up -d postgres
Step 3: Verify Connection
docker-compose logs postgres
Step 4: Run Setup Script
python setup_postgresql.py
🪟 Option 2: Windows Native Installation
Step 1: Download PostgreSQL
- Go to https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
- Download PostgreSQL for Windows (version 15 or later)
- Run the installer
Step 2: Installation Settings
- Password:
password(match .env file) - Port:
5432 - Username:
postgres - Database:
aegislm(create after installation)
Step 3: Start PostgreSQL Service
- Open Windows Services
- Find "postgresql-x64-15" (or similar version)
- Right-click → Start
Step 4: Create Database
Open Command Prompt and run:
psql -U postgres -c "CREATE DATABASE aegislm;"
Step 5: Test Connection
psql -U postgres -d aegislm
🌐 Option 3: Cloud PostgreSQL (Production Ready)
Neon (Recommended for Production)
- Sign up at https://neon.tech/
- Create new project
- Get connection string
- Update .env file:
DATABASE_URL="postgresql+asyncpg://user:password@ep-xxx.us-east-2.aws.neon.tech/aegislm?sslmode=require"
AWS RDS
- Go to AWS Console → RDS
- Create PostgreSQL instance
- Configure security group to allow your IP
- Update connection string
Railway
- Sign up at https://railway.app/
- Add PostgreSQL service
- Get connection string
- Update .env file
🔧 Configuration
Update .env file
# Database - PostgreSQL Production
DATABASE_URL="postgresql+asyncpg://postgres:password@localhost:5432/aegislm"
DATABASE_POOL_SIZE=10
DATABASE_MAX_OVERFLOW=20
Test Connection
python setup_postgresql.py
🚨 Troubleshooting
Connection Refused Error
- Check if PostgreSQL is running
- Verify port 5432 is available
- Check firewall settings
- Verify credentials in .env
Docker Issues
- Make sure Docker Desktop is running
- Check if port 5432 is already in use
- Try
docker system pruneto clean up
Permission Issues
- Run Command Prompt as Administrator
- Check PostgreSQL service status
- Verify user permissions
✅ Verification
After setup, run:
python setup_postgresql.py
You should see:
🎉 POSTGRESQL SETUP COMPLETE!
✅ PostgreSQL is ready for production!
✅ All database operations working!
✅ Health checks passing!
🔄 Migration from SQLite
If you have existing data in SQLite:
- Export data from SQLite
- Import to PostgreSQL
- Update .env to use PostgreSQL
- Run setup script
🚀 Production Deployment
For production:
- Use cloud PostgreSQL (Neon/AWS/Railway)
- Enable SSL
- Use environment variables for credentials
- Set up connection pooling
- Configure backups