Skip to main content

Database Requirements

Vestauth requires PostgreSQL 12 or higher for storing agent identities and public keys.

Supported Databases

  • Local PostgreSQL - For development and testing
  • Managed PostgreSQL - Production-ready options:
    • Supabase
    • AWS RDS
    • Google Cloud SQL
    • Azure Database for PostgreSQL
    • DigitalOcean Managed Databases
    • Heroku Postgres

Database Schema

Vestauth uses two main tables to store agent data:

agents Table

Stores agent identity information. Indexes:
  • Unique index on uid (index_agents_on_uid)

public_jwks Table

Stores agent public keys (JSON Web Keys). Indexes:
  • Index on agent_id (index_public_jwks_on_agent_id)
  • Unique index on kid (index_public_jwks_on_kid)
Foreign Keys:
  • agent_id references agents.id

Database Commands

Create Database

Create the vestauth_production database:
This command:
  1. Connects to PostgreSQL’s maintenance database (postgres)
  2. Checks if vestauth_production exists
  3. Creates the database if it doesn’t exist
The database name is extracted from the DATABASE_URL environment variable.For example, postgres://localhost/vestauth_production creates a database named vestauth_production.

Run Migrations

Apply database schema migrations:
Output:
Migrations are run sequentially and tracked in the knex_migrations table.

Drop Database

Destructive operation: This permanently deletes all agent data.
Use this only for development or when completely resetting your server.

Database Connection

Connection URL Format

Vestauth uses standard PostgreSQL connection URLs:

Local PostgreSQL

For local development:
.env
This connects to:
  • Host: localhost
  • Port: 5432 (default)
  • Database: vestauth_production
  • User: Current OS user
  • No password (peer authentication)

Managed PostgreSQL

For production with Supabase:
.env
For AWS RDS:
.env

Connection with SSL

Vestauth automatically configures SSL for database connections:
For strict SSL verification, you can modify the server code to provide CA certificates.

Migrations

Vestauth uses Knex.js for database migrations.

Migration Files

Migrations are located in src/server/db/migration/:

Migration Structure

Each migration file exports up and down functions:
20260223204000_create_agents_table.js

Migration Tracking

Knex creates a knex_migrations table to track which migrations have been applied:
Output:

Database Administration

Direct Database Access

Connect to your database using psql:
Local PostgreSQL
Managed PostgreSQL

Query Agent Data

View all agents:
View agent public keys:
Find a specific agent:

Backup and Restore

Backup your database:
Restore from backup:

Troubleshooting

Connection Issues

If you see missing DATABASE_URL error:
  1. Verify .env file exists and contains DATABASE_URL
  2. Check the URL format is correct
  3. Ensure PostgreSQL is running: pg_isready
If you see invalid DATABASE_URL error:
  • Check for typos in the connection string
  • Verify the URL follows the format: postgresql://user:pass@host:port/db

Migration Errors

If migrations fail:

Permission Errors

If you see permission denied errors:
  1. Ensure your PostgreSQL user has sufficient privileges
  2. Grant necessary permissions:

SSL Connection Issues

For managed databases requiring strict SSL: Modify src/lib/helpers/dbMigrate.js to include CA certificate:

Production Recommendations

1

Use Connection Pooling

Most managed PostgreSQL services provide connection pooling (e.g., Supabase Pooler, PgBouncer).Use the pooled connection URL:
2

Enable Automated Backups

Configure daily automated backups in your PostgreSQL provider:
  • Supabase: Automatic daily backups
  • AWS RDS: Configure automated snapshots
  • DigitalOcean: Enable daily backups
3

Monitor Database Performance

Set up monitoring for:
  • Connection count
  • Query performance
  • Storage usage
  • Replication lag (if applicable)
4

Configure Resource Limits

Set appropriate resource limits based on expected load:
  • Connection pool size
  • Memory allocation
  • CPU allocation