This document explains how to set up and use OAT-DB with PostgreSQL storage.
OAT-DB now supports two storage backends:
- In-Memory Store (default) - For development and testing
- PostgreSQL Store - For production use with persistent storage
The easiest way to get started is using Docker Compose, which runs both PostgreSQL and the OAT-DB service:
# Start the full stack (PostgreSQL + OAT-DB + pgAdmin)
docker-compose up -d
# View logs
docker-compose logs -f
# Stop everything
docker-compose downThis will start:
- PostgreSQL database on port 5432
- OAT-DB REST API on port 3001
- pgAdmin (database management UI) on port 5050
- OAT-DB API: http://localhost:3001
- API Documentation: http://localhost:3001/docs
- pgAdmin: http://localhost:5050 (admin@oatdb.com / admin)
Install and start PostgreSQL:
# On macOS (with Homebrew)
brew install postgresql
brew services start postgresql
# On Ubuntu/Debian
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
# Create database
createdb -U postgres oatdbCopy the example environment file and configure it:
cp .env.example .envEdit .env to configure your setup:
# Use PostgreSQL
OAT_DATABASE_TYPE=postgres
DATABASE_URL=postgres://postgres:password@localhost:5432/oatdb
# Server configuration
OAT_SERVER_HOST=127.0.0.1
OAT_SERVER_PORT=3001
# Optional: Load seed data on startup
LOAD_SEED_DATA=true# Build and run
cargo run
# Or with specific log level
RUST_LOG=info cargo runThe application will automatically:
- Connect to PostgreSQL
- Run database migrations
- Start the REST API server
| Variable | Description | Default | Example |
|---|---|---|---|
OAT_DATABASE_TYPE |
Database type | memory |
postgres |
DATABASE_URL |
PostgreSQL connection string | - | postgres://user:pass@host:port/db |
OAT_SERVER_HOST |
Server bind address | 127.0.0.1 |
0.0.0.0 |
OAT_SERVER_PORT |
Server port | 3001 |
8080 |
OAT_DATABASE_MAX_CONNECTIONS |
Connection pool size | 20 |
50 |
LOAD_SEED_DATA |
Load example data on startup | false |
true |
RUST_LOG |
Log level | info |
debug |
You can also use a config.toml file:
[server]
host = "127.0.0.1"
port = 3001
[database]
type = "postgres"
connection_string = "postgres://postgres:password@localhost:5432/oatdb"
max_connections = 20The PostgreSQL integration uses the following tables:
- databases - Database definitions
- branches - Git-like branches for each database
- schemas - Schema definitions (one per branch)
- class_definitions - Class/type definitions within schemas
- instances - Instance data within branches
All tables support JSONB for flexible property storage and include proper indexing for performance.
# Use default in-memory store
cargo run
# Or explicitly
OAT_DATABASE_TYPE=memory cargo run# Start PostgreSQL with Docker
docker run --name oatdb-postgres \
-e POSTGRES_DB=oatdb \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=password \
-p 5432:5432 -d postgres:15
# Run OAT-DB with PostgreSQL
OAT_DATABASE_TYPE=postgres \
DATABASE_URL=postgres://postgres:password@localhost:5432/oatdb \
cargo runDatabase migrations are automatically applied on startup. Migration files are in the migrations/ directory.
To create a new migration:
# Create new migration file
touch migrations/002_your_migration.sqlThe REST API is identical regardless of storage backend:
# List databases
curl http://localhost:3001/databases
# Create a database
curl -X POST http://localhost:3001/databases \
-H "Content-Type: application/json" \
-d '{"name": "my-db", "description": "Test database"}'
# View API documentation
open http://localhost:3001/docsUse pgAdmin (included in Docker Compose):
- Open http://localhost:5050
- Login with admin@oatdb.com / admin
- Add server: postgres / 5432 / oatdb / postgres / password
# Backup
pg_dump -U postgres -h localhost oatdb > backup.sql
# Restore
psql -U postgres -h localhost oatdb < backup.sql# Check connection pool status (add logging to your app)
RUST_LOG=sqlx=debug cargo run
# Monitor PostgreSQL
docker-compose exec postgres psql -U postgres -d oatdb -c "SELECT * FROM pg_stat_activity;"-
Connection Refused
- Ensure PostgreSQL is running
- Check connection string format
- Verify firewall settings
-
Migration Errors
- Check PostgreSQL version compatibility
- Ensure database user has CREATE privileges
- Review migration SQL syntax
-
Performance Issues
- Increase connection pool size
- Add database indexes for your query patterns
- Monitor slow queries
# Application logs
RUST_LOG=debug cargo run
# Docker Compose logs
docker-compose logs -f oat-db-rust
docker-compose logs -f postgresFor production deployment:
- Use a managed PostgreSQL service (AWS RDS, Google Cloud SQL, etc.)
- Set appropriate connection pool sizes
- Enable SSL connections
- Configure backup strategies
- Set up monitoring and alerting
- Use container orchestration (Kubernetes, Docker Swarm)
Example production environment:
OAT_DATABASE_TYPE=postgres
DATABASE_URL=postgres://user:password@prod-db.example.com:5432/oatdb?sslmode=require
OAT_SERVER_HOST=0.0.0.0
OAT_SERVER_PORT=3001
OAT_DATABASE_MAX_CONNECTIONS=50
RUST_LOG=info