Documenso

Database Configuration

Configure PostgreSQL connection strings, pooling, SSL, migrations, and performance tuning for your Documenso deployment.

Supported Databases

Documenso requires PostgreSQL 14 or later. No other databases are supported.

PostgreSQL provides the reliability, performance, and feature set required for document signing workflows, including:

  • ACID compliance for transaction integrity
  • JSON support for flexible metadata storage
  • Full-text search capabilities
  • Robust backup and replication options

Connection String Format

PostgreSQL connection strings follow this format:

postgresql://[user]:[password]@[host]:[port]/[database]?[parameters]

Components

ComponentDescriptionExample
userDatabase usernamedocumenso
passwordDatabase password (URL-encoded)secretpass
hostDatabase server hostname or IPlocalhost
portDatabase port5432
databaseDatabase namedocumenso
parametersAdditional connection optionssslmode=require

Examples

Local development:

postgresql://documenso:password@localhost:5432/documenso

Remote server with SSL:

postgresql://documenso:password@db.example.com:5432/documenso?sslmode=require

With special characters in password:

URL-encode special characters in passwords. For example, p@ss#word becomes p%40ss%23word:

postgresql://documenso:p%40ss%23word@localhost:5432/documenso

Environment Variables

Documenso uses two database connection variables:

VariablePurpose
NEXT_PRIVATE_DATABASE_URLPrimary connection for application queries
NEXT_PRIVATE_DIRECT_DATABASE_URLDirect connection for migrations and schema changes

Basic Configuration

When not using a connection pooler, set both variables to the same value:

NEXT_PRIVATE_DATABASE_URL=postgresql://user:password@host:5432/documenso
NEXT_PRIVATE_DIRECT_DATABASE_URL=postgresql://user:password@host:5432/documenso

Automatic Detection

Documenso automatically detects common database environment variable formats used by hosting providers:

Provider VariableMaps To
DATABASE_URLNEXT_PRIVATE_DATABASE_URL
POSTGRES_URLNEXT_PRIVATE_DATABASE_URL
POSTGRES_PRISMA_URLNEXT_PRIVATE_DATABASE_URL
DATABASE_URL_UNPOOLEDNEXT_PRIVATE_DIRECT_DATABASE_URL
POSTGRES_URL_NON_POOLINGNEXT_PRIVATE_DIRECT_DATABASE_URL

If your hosting provider sets these variables, Documenso will use them automatically.

Connection Pooling

Connection pooling improves performance by reusing database connections instead of creating new ones for each request.

When to Use Pooling

Use connection pooling when:

  • Running multiple application instances
  • Deploying to serverless environments
  • Handling high concurrent request volumes
  • Your database has connection limits

PgBouncer Configuration

When using PgBouncer or similar poolers, configure two connection strings:

  1. Pooled connection for application queries
  2. Direct connection for migrations (bypasses the pooler)
# Pooled connection (through PgBouncer)
NEXT_PRIVATE_DATABASE_URL=postgresql://user:password@pooler-host:6432/documenso?pgbouncer=true

# Direct connection (bypasses PgBouncer)
NEXT_PRIVATE_DIRECT_DATABASE_URL=postgresql://user:password@db-host:5432/documenso

Migrations must use a direct connection. Running migrations through a connection pooler will fail.

Prisma Connection Pool

Documenso uses Prisma, which maintains its own connection pool. Configure pool size with connection string parameters:

postgresql://user:password@host:5432/documenso?connection_limit=10&pool_timeout=30
ParameterDescriptionDefault
connection_limitMaximum connections in the pool10
pool_timeoutSeconds to wait for available connection10

SSL/TLS Connections

Enabling SSL

Add SSL parameters to your connection string:

postgresql://user:password@host:5432/documenso?sslmode=require

SSL Modes

ModeDescription
disableNo SSL (not recommended for production)
allowTry non-SSL first, fall back to SSL
preferTry SSL first, fall back to non-SSL
requireRequire SSL, but don't verify certificate
verify-caRequire SSL and verify server certificate
verify-fullRequire SSL, verify certificate, and check hostname

For production, use require at minimum. Use verify-full when your CA certificate is available.

Custom Certificates

When connecting to databases with self-signed or private CA certificates:

postgresql://user:password@host:5432/documenso?sslmode=verify-full&sslrootcert=/path/to/ca.crt

For Docker deployments, mount the certificate file:

docker run -d \
  -v /path/to/ca.crt:/etc/ssl/certs/db-ca.crt:ro \
  -e NEXT_PRIVATE_DATABASE_URL="postgresql://user:password@host:5432/documenso?sslmode=verify-full&sslrootcert=/etc/ssl/certs/db-ca.crt" \
  documenso/documenso:latest

Running Migrations

Database migrations update your schema when upgrading Documenso.

Automatic Migrations

When running Documenso via Docker, migrations run automatically on container startup. No manual intervention is required.

Manual Migrations

For manual deployments or troubleshooting:

# Apply pending migrations
npm run prisma:migrate-deploy

# Or using npx directly
npx prisma migrate deploy

Always back up your database before running migrations, especially for major version upgrades.

Migration Commands

CommandPurpose
prisma:migrate-deployApply pending migrations (production)
prisma:migrate-devCreate and apply migrations (development)
prisma:migrate-resetReset database and apply all migrations

Troubleshooting Migrations

Managed Database Services

Backup Recommendations

Backup Strategies

StrategyFrequencyRetentionUse Case
Automated snapshotsDaily7-30 daysPoint-in-time recovery
Logical backupsDaily/Weekly30-90 daysLong-term retention
Continuous replicationReal-time24-72 hoursDisaster recovery

PostgreSQL Backup Commands

Create a logical backup:

pg_dump -h host -U user -d documenso -F c -f documenso_backup.dump

Restore from backup:

pg_restore -h host -U user -d documenso -c documenso_backup.dump

Managed Service Backups

Most managed database services provide automated backups:

Daily backups with point-in-time recovery (Pro plan)
Automatic branching for instant recovery
Automated backups with configurable retention
Automated and on-demand backups
Automatic backups with geo-redundancy options

Always test your backup restoration process. Untested backups may not work when needed.

Performance Tuning

PostgreSQL Configuration

Key parameters for Documenso workloads:

ParameterRecommended ValueDescription
shared_buffers25% of RAMMemory for caching data
effective_cache_size75% of RAMPlanner's estimate of available cache
work_mem64MB-256MBMemory per sort/hash operation
maintenance_work_mem512MB-1GBMemory for maintenance operations
max_connections100-200Maximum concurrent connections

Connection Limits

Calculate your connection limit:

max_connections = (application_instances × connection_pool_size) + admin_overhead

Example: 3 app instances with pool size 10 = (3 × 10) + 10 = 40 connections minimum.

Indexing

Documenso includes necessary indexes by default. Additional indexes may help for:

  • Custom reporting queries
  • High-volume document searches
  • Audit log analysis

Check for slow queries:

SELECT query, calls, mean_time, total_time
FROM pg_stat_statements
ORDER BY total_time DESC
LIMIT 10;

Monitoring

Monitor these metrics:

MetricWarning ThresholdAction
Connection usage> 80%Increase limits or add pooling
Disk usage> 80%Add storage or archive old data
Cache hit ratio< 95%Increase shared_buffers
Long-running queries> 30 secondsOptimize query or add indexes

Troubleshooting


See Also

On this page