PostgreSQL
PostgreSQL Database Connection
Section titled “PostgreSQL Database Connection”PostgreSQL is a powerful, open-source object-relational database system. Datablast connects to PostgreSQL servers using standard connection parameters. This guide covers how to gather and configure the required credentials for both self-hosted and cloud PostgreSQL instances.
1. Required Connection Information
Section titled “1. Required Connection Information”Essential Parameters
Section titled “Essential Parameters”| Parameter | Description | Default |
|---|---|---|
| Host | PostgreSQL server address (localhost, IP, or domain name) | localhost |
| Port | PostgreSQL server port number | 5432 |
| Database | Database name you want to connect to | postgres |
| Schema | Schema within the database (optional, defaults to ‘public’) | public |
| User | PostgreSQL username with appropriate permissions | - |
| Password | Password for the PostgreSQL user | - |
Connection String Format
Section titled “Connection String Format”postgresql://user:password@host:port/database2. Gathering PostgreSQL Credentials
Section titled “2. Gathering PostgreSQL Credentials”From Your Database Administrator
Section titled “From Your Database Administrator”Contact your DBA for:
- Server hostname or IP address
- Database name
- Schema name (if using custom schemas)
- Username and password
- Port number (if different from 5432)
- SSL requirements
From Cloud Providers
Section titled “From Cloud Providers”Amazon RDS PostgreSQL:
- Endpoint:
mydb.abc123.us-east-1.rds.amazonaws.com - Port: 5432 (default) or custom
- SSL connections available
- Master username and password
Supabase:
- Connection string provided in dashboard
- Uses connection pooling by default
- SSL/TLS required for connections
- Direct and pooled connection options
Google Cloud SQL:
- Instance connection name
- Public or private IP options
- Cloud SQL Proxy for secure connections
- IAM database authentication available
Azure Database for PostgreSQL:
- Server name:
servername.postgres.database.azure.com - Username format:
username@servername - SSL connection required
Heroku PostgreSQL:
- DATABASE_URL environment variable
- Color-coded database names
- Connection limit based on plan
3. Testing Connection via Command Line
Section titled “3. Testing Connection via Command Line”Basic Connection Command
Section titled “Basic Connection Command”psql -h HOST -U USER -d DATABASE -p PORTLong Form Options
Section titled “Long Form Options”psql --host=HOST --username=USER --dbname=DATABASE --port=PORTConnection Examples
Section titled “Connection Examples”Local PostgreSQL:
psql -h localhost -U myuser -d mydatabase -p 5432Remote PostgreSQL:
psql -h db.example.com -U appuser -d production_db -p 5432With SSL:
psql "host=secure-db.com port=5432 dbname=mydb user=myuser sslmode=require"Using Connection URI:
psql postgresql://user:password@host:port/database💡 Security Tip: PostgreSQL will prompt for password when using
-Uoption. Never include passwords in command history or scripts.
4. Configure Datablast Connection
Section titled “4. Configure Datablast Connection”Connection Form Fields
Section titled “Connection Form Fields”| Field | Example Value | Notes |
|---|---|---|
| Connection Name | Production PostgreSQL | Friendly name for the UI |
| Host | db.mycompany.com | Server address or IP |
| Port | 5432 | Usually 5432 for PostgreSQL |
| Database | analytics_db | Database name |
| Schema | public | Schema within database |
| User | datablast_user | PostgreSQL username |
| Password | •••••••••••• | User password (hidden) |
| Description | Main analytics database | Optional connection notes |
Advanced Connection Options
Section titled “Advanced Connection Options”SSL Mode:
disable- No SSLrequire- SSL requiredverify-ca- Verify CA certificateverify-full- Full certificate verification
Connection Pooling:
- Useful for high-traffic applications
- PgBouncer integration
- Connection limits per user
5. Security Best Practices
Section titled “5. Security Best Practices”User Permissions
Section titled “User Permissions”Create a dedicated PostgreSQL user for Datablast:
-- Create userCREATE USER datablast WITH PASSWORD 'secure_password';
-- Grant database connectionGRANT CONNECT ON DATABASE analytics_db TO datablast;
-- Grant schema usageGRANT USAGE ON SCHEMA public TO datablast;
-- Grant table accessGRANT SELECT ON ALL TABLES IN SCHEMA public TO datablast;
-- Grant access to future tablesALTER DEFAULT PRIVILEGES IN SCHEMA publicGRANT SELECT ON TABLES TO datablast;Connection Security
Section titled “Connection Security”- Use SSL/TLS: Enable encrypted connections for remote databases
- Limit Host Access: Configure
pg_hba.conffor specific IP addresses - Minimal Permissions: Grant only necessary database and table access
- Strong Authentication: Use SCRAM-SHA-256 or certificate-based auth
Network Configuration
Section titled “Network Configuration”PostgreSQL Configuration (postgresql.conf):
listen_addresses = 'localhost,10.0.0.0/8'ssl = onssl_cert_file = 'server.crt'ssl_key_file = 'server.key'Host-Based Authentication (pg_hba.conf):
# TYPE DATABASE USER ADDRESS METHODhost analytics datablast 10.0.0.0/8 scram-sha-256hostssl all all 0.0.0.0/0 scram-sha-2566. Password File Configuration
Section titled “6. Password File Configuration”Using .pgpass File
Section titled “Using .pgpass File”Avoid entering passwords repeatedly by creating a password file:
Linux/macOS (~/.pgpass):
host:port:database:user:passworddb.example.com:5432:analytics_db:datablast_user:my_secure_passwordWindows (%APPDATA%\postgresql\pgpass.conf):
host:port:database:user:passworddb.example.com:5432:analytics_db:datablast_user:my_secure_passwordSet Proper Permissions:
chmod 600 ~/.pgpassEnvironment Variables
Section titled “Environment Variables”export PGHOST=db.example.comexport PGPORT=5432export PGDATABASE=analytics_dbexport PGUSER=datablast_userexport PGPASSWORD=my_secure_password7. Troubleshooting
Section titled “7. Troubleshooting”Connection Refused
Section titled “Connection Refused”- Check PostgreSQL service:
systemctl status postgresql - Verify port:
netstat -tlnp | grep 5432 - Test network connectivity:
telnet host 5432 - Check firewall rules: Ensure port 5432 is open
Authentication Failed
Section titled “Authentication Failed”- Verify credentials: Double-check username and password
- Check pg_hba.conf: Ensure host-based authentication allows your connection
- User exists: Confirm user exists in PostgreSQL
- Database access: Verify user has CONNECT permission
SSL/TLS Issues
Section titled “SSL/TLS Issues”- SSL mode mismatch: Server requires SSL but client doesn’t use it
- Certificate problems: Invalid or expired SSL certificates
- Protocol versions: Ensure compatible TLS versions
Permission Denied
Section titled “Permission Denied”- Schema access: User needs USAGE permission on schema
- Table access: User needs SELECT permission on tables
- Database access: User needs CONNECT permission on database
8. Common Cloud Provider Settings
Section titled “8. Common Cloud Provider Settings”Amazon RDS PostgreSQL
Section titled “Amazon RDS PostgreSQL”Host: mydb.cluster-xyz.us-east-1.rds.amazonaws.comPort: 5432Database: postgresSSL Mode: requireSupabase
Section titled “Supabase”Host: db.your-project.supabase.coPort: 5432Database: postgresSSL Mode: requireGoogle Cloud SQL
Section titled “Google Cloud SQL”Host: 1.2.3.4 (Public IP)Port: 5432Database: postgresSSL Mode: requireAzure Database for PostgreSQL
Section titled “Azure Database for PostgreSQL”Host: myserver.postgres.database.azure.comPort: 5432User: username@myserverSSL Mode: requireHeroku PostgreSQL
Section titled “Heroku PostgreSQL”# Use DATABASE_URL from Heroku configheroku config:get DATABASE_URL9. Performance Optimization
Section titled “9. Performance Optimization”Connection Settings
Section titled “Connection Settings”-- Show current connection limitsSELECT setting FROM pg_settings WHERE name = 'max_connections';
-- Show active connectionsSELECT count(*) FROM pg_stat_activity;
-- Check connection pool status (if using PgBouncer)SHOW POOLS;Query Performance
Section titled “Query Performance”-- Enable query logging for analysisSET log_statement = 'all';SET log_min_duration_statement = 1000;
-- Analyze slow queriesSELECT query, mean_exec_time, callsFROM pg_stat_statementsORDER BY mean_exec_time DESCLIMIT 10;Useful Links
Section titled “Useful Links”Always use encrypted connections for production databases and implement proper user access controls with minimal required permissions.