Connecting to Your Database
Once your database is running, you can retrieve connection details from the database detail page.
Viewing Connection Information
- Navigate to Databases in the sidebar
- Click on your database name
- The connection details are displayed in the Connection Information card
Connection Details
Each database provides the following connection information:
| Field | Description |
|---|---|
| Connection String | Full URI for connecting to your database |
| Host | Database hostname |
| Port | Database port number |
| Username | Database user |
| Password | Database password |
| Database | Database name |
Use the copy button next to each field to copy values to your clipboard.
Connection String Formats
PostgreSQL
postgresql://username:password@host:5432/database
Example:
postgresql://postgres:abc123@mydb.db.hostless.cloud:5432/mydb
MySQL
mysql://username:password@host:3306/database
Example:
mysql://mysql:abc123@mydb.db.hostless.cloud:3306/mydb
MongoDB
mongodb://username:password@host:27017/database
Example:
mongodb://root:abc123@mydb.db.hostless.cloud:27017/mydb
Using Connection Strings in Your App
The recommended approach is to store the connection string in an environment variable. If you linked your database to an app during creation, this is done automatically.
Manual Configuration
- Navigate to your app's Environment Variables settings
- Add a new variable (e.g.,
DATABASE_URL) - Paste your connection string as the value
- Save and redeploy your app
Framework Examples
Node.js (pg)
const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
Python (psycopg2)
import os
import psycopg2
conn = psycopg2.connect(os.environ['DATABASE_URL'])
Django
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default=os.environ['DATABASE_URL'])
}
TLS/SSL
All Hostless databases have TLS encryption enabled by default. Your connections are automatically secured without additional configuration.
Most database drivers will automatically use TLS when connecting to Hostless databases. If you need to explicitly enable SSL, refer to your driver's documentation.
Connection Pooling (PostgreSQL)
PostgreSQL databases include PgBouncer, a connection pooler that efficiently manages database connections. This is transparent to your application - simply connect using the provided connection string.
Benefits of connection pooling:
- Reduced connection overhead
- Better handling of many concurrent connections
- Improved performance for serverless workloads
Troubleshooting
Connection Refused
- Verify your database status is RUNNING
- Check that you're using the correct host and port
- Ensure your connection string is properly URL-encoded
Authentication Failed
- Double-check your username and password
- Copy the credentials directly from the dashboard to avoid typos
- Ensure special characters in passwords are properly escaped
Database Not Found
- Verify you're connecting to the correct database name
- The database name matches your Hostless database name