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
| Component | Description | Example |
|---|---|---|
user | Database username | documenso |
password | Database password (URL-encoded) | secretpass |
host | Database server hostname or IP | localhost |
port | Database port | 5432 |
database | Database name | documenso |
parameters | Additional connection options | sslmode=require |
Examples
Local development:
postgresql://documenso:password@localhost:5432/documensoRemote server with SSL:
postgresql://documenso:password@db.example.com:5432/documenso?sslmode=requireWith 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/documensoEnvironment Variables
Documenso uses two database connection variables:
| Variable | Purpose |
|---|---|
NEXT_PRIVATE_DATABASE_URL | Primary connection for application queries |
NEXT_PRIVATE_DIRECT_DATABASE_URL | Direct 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/documensoAutomatic Detection
Documenso automatically detects common database environment variable formats used by hosting providers:
| Provider Variable | Maps To |
|---|---|
DATABASE_URL | NEXT_PRIVATE_DATABASE_URL |
POSTGRES_URL | NEXT_PRIVATE_DATABASE_URL |
POSTGRES_PRISMA_URL | NEXT_PRIVATE_DATABASE_URL |
DATABASE_URL_UNPOOLED | NEXT_PRIVATE_DIRECT_DATABASE_URL |
POSTGRES_URL_NON_POOLING | NEXT_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:
- Pooled connection for application queries
- 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/documensoMigrations 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| Parameter | Description | Default |
|---|---|---|
connection_limit | Maximum connections in the pool | 10 |
pool_timeout | Seconds to wait for available connection | 10 |
SSL/TLS Connections
Enabling SSL
Add SSL parameters to your connection string:
postgresql://user:password@host:5432/documenso?sslmode=requireSSL Modes
| Mode | Description |
|---|---|
disable | No SSL (not recommended for production) |
allow | Try non-SSL first, fall back to SSL |
prefer | Try SSL first, fall back to non-SSL |
require | Require SSL, but don't verify certificate |
verify-ca | Require SSL and verify server certificate |
verify-full | Require 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.crtFor 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:latestRunning 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 deployAlways back up your database before running migrations, especially for major version upgrades.
Migration Commands
| Command | Purpose |
|---|---|
prisma:migrate-deploy | Apply pending migrations (production) |
prisma:migrate-dev | Create and apply migrations (development) |
prisma:migrate-reset | Reset database and apply all migrations |
Troubleshooting Migrations
Managed Database Services
Backup Recommendations
Backup Strategies
| Strategy | Frequency | Retention | Use Case |
|---|---|---|---|
| Automated snapshots | Daily | 7-30 days | Point-in-time recovery |
| Logical backups | Daily/Weekly | 30-90 days | Long-term retention |
| Continuous replication | Real-time | 24-72 hours | Disaster recovery |
PostgreSQL Backup Commands
Create a logical backup:
pg_dump -h host -U user -d documenso -F c -f documenso_backup.dumpRestore from backup:
pg_restore -h host -U user -d documenso -c documenso_backup.dumpManaged Service Backups
Most managed database services provide automated backups:
Always test your backup restoration process. Untested backups may not work when needed.
Performance Tuning
PostgreSQL Configuration
Key parameters for Documenso workloads:
| Parameter | Recommended Value | Description |
|---|---|---|
shared_buffers | 25% of RAM | Memory for caching data |
effective_cache_size | 75% of RAM | Planner's estimate of available cache |
work_mem | 64MB-256MB | Memory per sort/hash operation |
maintenance_work_mem | 512MB-1GB | Memory for maintenance operations |
max_connections | 100-200 | Maximum concurrent connections |
Connection Limits
Calculate your connection limit:
max_connections = (application_instances × connection_pool_size) + admin_overheadExample: 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:
| Metric | Warning Threshold | Action |
|---|---|---|
| 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 seconds | Optimize query or add indexes |
Troubleshooting
See Also
- Environment Variables - Complete configuration reference
- Storage Configuration - Set up document storage
- Backups - Backup strategies and procedures
- Upgrades - Upgrade procedures and migration handling