Database Connection Strings & Methods: PostgreSQL, MySQL, MongoDB | Nife
Connect your applications to managed databases using connection details and authentication.
Getting Connection Details#
After Database Creation#
You'll receive connection details:
- Hostname:
db-prod-001.database.nifetency.com - Port:
5432(PostgreSQL),3306(MySQL), etc. - Username:
root - Password: Your set password
- Database Name:
postgres(default)
Finding Existing Credentials#
- Go to Databases page
- Click database name
- Click Connection Details
- Copy hostname, port, username
Password: Store separately for security.
Connection Methods#
Method 1: Connection String#
Use connection string format for your database type:
PostgreSQL:
MySQL:
MongoDB:
Redis:
Method 2: Individual Parameters#
Provide individual connection parameters:
Method 3: Environment Variables#
Set connection details as environment variables:
Example:
Application Examples#
Node.js (PostgreSQL)#
Python (PostgreSQL)#
Python (MongoDB)#
Node.js (MongoDB)#
Docker Compose#
Kubernetes#
Connection Tools#
GUI Database Clients#
For PostgreSQL/MySQL:
- DBeaver: Free, feature-rich, cross-platform
- MySQL Workbench: Official MySQL client
- pgAdmin: Web-based PostgreSQL admin
- HeidiSQL: Free MySQL/PostgreSQL client
For MongoDB:
- MongoDB Compass: Official client
- NoSQL Booster: Advanced client
- Robo 3T: Community MongoDB client
For Redis:
- Redis Desktop Manager: GUI client
- RedisInsight: Official Redis client
Command Line Tools#
PostgreSQL:
MySQL:
MongoDB:
Redis:
Testing Connection#
Test Before Using#
Always test connection before deploying:
Bash script to test:
Python test:
Connection Pool Configuration#
What is Connection Pooling?#
Connection pooling reuses database connections instead of creating new ones each time. This improves performance and reduces resource usage.
Recommended Pool Sizes#
| Application Type | Pool Size | Max Connections |
|---|---|---|
| Small app | 2-5 | 10 |
| Medium app | 5-10 | 20 |
| Large app | 10-20 | 50 |
| Enterprise | 20+ | 100+ |
Configuring Pool (Node.js Example)#
SSL/TLS Connections#
Enable Encryption#
All connections support SSL/TLS encryption:
PostgreSQL with SSL:
MySQL with SSL:
Recommendation: Always use SSL/TLS in production.
Troubleshooting Connection#
Problem: Connection Refused#
Symptoms:
Solutions:
- Verify hostname is correct
- Verify port is correct (5432 for PostgreSQL, 3306 for MySQL)
- Check credentials
- Verify database exists
- Check firewall/network rules
- Ensure application IP is whitelisted
Problem: Authentication Failed#
Symptoms:
Solutions:
- Verify password is correct
- Check username is correct (usually 'root')
- Verify database name
- Reset password if forgotten
- Copy password directly from dashboard
Problem: Timeout#
Symptoms:
Solutions:
- Check network connectivity
- Increase timeout value in connection
- Verify database is running
- Check firewall rules
- Contact support if database is down
Problem: Too Many Connections#
Symptoms:
Solutions:
- Enable connection pooling
- Close unused connections
- Reduce pool size if needed
- Scale up database plan
- Monitor active connections
Security Best Practices#
1. Never Hardcode Credentials#
Bad:
Good:
2. Use Connection Pooling#
Reuse connections instead of creating new ones.
3. Use SSL/TLS#
Always encrypt connections in production.
4. Restrict Network Access#
- Use firewall rules
- Allow only necessary IPs
- Use VPN if possible
5. Change Default Passwords#
Don't use root account for applications.
6. Monitor Access#
- Check connection logs
- Monitor for unusual activity
- Set up alerts
7. Rotate Credentials#
- Change passwords periodically
- After team changes
- If credentials exposed
Next Steps#
- Managing Databases - Scale and monitor
- Backup & Recovery - Data protection
- Database Best Practices - Optimization tips
Support#
Connection issues?
- Check sections above
- Verify credentials
- Test with command line first
- Contact support: [email protected]