Creating a PostgreSQL Database
Navigate to Databases
In your Dokploy dashboard, select your environment and click Add Database > PostgreSQL.
Configure Basic Settings
Fill in the required information:
- Name: Display name for the database (e.g., “Production DB”)
- App Name: Internal DNS name (e.g.,
postgres-prod) - Description: Optional notes about the database
- Docker Image: PostgreSQL version (default:
postgres:18)
Connection Information
Once deployed, you can connect to your PostgreSQL database using these credentials.- Internal Connection
- External Connection
Applications in the same environment connect via internal DNS:Connection String Example:
Configuration
Environment Variables
Customize PostgreSQL behavior by adding environment variables:Environment variables are set during container creation. Changes require redeploying the database.
Resource Limits
Allocate resources based on your workload:| Resource | Recommended for Small | Recommended for Large |
|---|---|---|
| Memory Reservation | 256MB | 2GB |
| Memory Limit | 512MB | 4GB |
| CPU Reservation | 0.25 | 1.0 |
| CPU Limit | 0.5 | 2.0 |
Custom Docker Image
Use specific PostgreSQL versions or Alpine variants:Database Operations
Start and Stop
Control database availability through the UI:- Start: Brings the database online (status:
done) - Stop: Gracefully shuts down the database (status:
idle) - Reload: Restarts the container to apply changes
Stopping a database does not delete data. All data persists in the volume.
Rebuild Database
Completely rebuild the database container while preserving data:- Navigate to Settings > Rebuild
- Confirm the rebuild operation
- Wait for the container to rebuild and restart
Volume Management
PostgreSQL data is stored in a Docker volume automatically created with the pattern:/var/lib/postgresql/data(most versions)- Version-specific paths for compatibility
Backup Volume Data
See the Database Backups page for automated backup configuration.Advanced Configuration
Custom Command and Arguments
Override PostgreSQL startup configuration: Command:Health Checks
Configure Docker Swarm health checks for automatic recovery:Restart Policy
Ensure PostgreSQL restarts automatically on failure:Common Use Cases
- Application Database
- Analytics Workload
- Development
Standard configuration for web applications:
Monitoring and Logs
View PostgreSQL logs in the Dokploy dashboard:- Navigate to your PostgreSQL service
- Click Logs tab
- View real-time container output
Troubleshooting
Database won't start
Database won't start
Check the container logs for errors:
- Navigate to Logs tab
- Look for initialization errors
- Common issues:
- Invalid credentials format
- Insufficient permissions on volume
- Port conflicts (if using external port)
Connection refused
Connection refused
Verify connection settings:
- Internal: Use app name (e.g.,
postgres-prod) notlocalhost - External: Ensure external port is configured and deployed
- Check that the database status is
done(running) - Verify firewall rules allow connections
Out of memory errors
Out of memory errors
PostgreSQL may be using more memory than allocated:
- Increase Memory Limit in settings
- Adjust PostgreSQL memory settings:
- Redeploy the database
Slow query performance
Slow query performance
Optimize PostgreSQL configuration:
- Increase memory allocation
- Tune environment variables:
- Consider upgrading to a faster disk (SSD recommended)
Next Steps
Setup Backups
Configure automated PostgreSQL backups
MySQL
Deploy a MySQL database