Database Setup

Configure PostgreSQL for Authority.

Requirements

  • PostgreSQL 13 or higher

  • 100MB minimum disk space

  • Recommended: SSD storage

Creating the Database

Using psql

# Create database
psql -c "CREATE DATABASE authority_db;"

# Create user (optional)
psql -c "CREATE USER authority WITH PASSWORD 'secure_password';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE authority_db TO authority;"

Using createdb

createdb authority_db

Connection String

Configure the DATABASE_URL environment variable:

SSL Mode

For production, enable SSL:

SSL modes:

  • disable - No SSL

  • require - SSL required, no verification

  • verify-ca - Verify server certificate

  • verify-full - Verify server certificate and hostname

Running Migrations

Migrations create the required tables:

Tables Created

Table
Description

users

User accounts

clients

OAuth clients

access_tokens

Access tokens

refresh_tokens

Refresh tokens

authorization_codes

Authorization codes

device_codes

Device authorization codes

scopes

OAuth scopes

audit_logs

Audit trail

sessions

User sessions

Seeding Data

Create initial data:

This creates:

  • Default admin user

  • Common OAuth scopes

  • System settings

Backup and Restore

Backup

With compression:

Restore

From compressed:

Connection Pooling

For production, configure connection pooling:

Using PgBouncer

Update connection string:

Performance Tuning

PostgreSQL Configuration

Indexes

Authority creates necessary indexes during migration. For additional performance, consider:

Troubleshooting

Connection refused

Check PostgreSQL is running:

Authentication failed

Verify credentials and pg_hba.conf:

Database does not exist

Create the database:

Permission denied

Grant permissions:

Next Steps

Last updated

Was this helpful?