Skip to content

Database Setup

Configure the database for Ops Atlas.

Docker

yaml
services:
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: opsatlas
      POSTGRES_USER: opsatlas
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data

External PostgreSQL

bash
# Create database
psql -U postgres << 'SQL'
CREATE DATABASE opsatlas;
CREATE USER opsatlas WITH ENCRYPTED PASSWORD 'your-password';
GRANT ALL PRIVILEGES ON DATABASE opsatlas TO opsatlas;
SQL

Connection string:

DATABASE_URL=postgres://opsatlas:your-password@db-host:5432/opsatlas

SQLite (Development Only)

For quick local development:

bash
DATABASE_URL=sqlite:./data/opsatlas.db

WARNING

SQLite is not recommended for production use.

Connection Pooling

For high-traffic deployments, use PgBouncer:

yaml
services:
  pgbouncer:
    image: edoburu/pgbouncer
    environment:
      DATABASE_URL: postgres://user:pass@db:5432/opsatlas
      POOL_MODE: transaction
      MAX_CLIENT_CONN: 100

Migrations

Migrations run automatically on startup. To run manually:

bash
# Check status
ops-atlas db status

# Run migrations
ops-atlas db migrate

# Rollback
ops-atlas db rollback

Backup & Restore

bash
# Backup
pg_dump -U opsatlas opsatlas > backup_$(date +%Y%m%d).sql

# Restore
psql -U opsatlas opsatlas < backup_20250101.sql

Released under the MIT License.