Connecting to PostgreSQL
Connect Agent M to your PostgreSQL database, whether it's a local instance, cloud provider, or managed service.
Prerequisites
- A PostgreSQL instance (local, cloud, or managed)
- Connection credentials (username and password)
Connection String Format
PostgreSQL uses connection strings (also called connection URIs) to specify how to connect to your database:
postgresql://[username]:[password]@[host]:[port]/[database]You can also use postgres:// instead of postgresql:// - both are valid.
Connection Methods
1Local PostgreSQL
For a local PostgreSQL instance running on your machine:
postgresql://localhost:5432/mydbWith authentication:
postgresql://username:password@localhost:5432/mydb2Cloud Providers (AWS RDS, Google Cloud SQL, etc.)
Most cloud providers give you a connection string in their console:
- AWS RDS: Go to your RDS instance → Connectivity & security → Endpoint
- Google Cloud SQL: Go to your instance → Overview → Connect to this instance
- Azure Database: Go to your server → Connection strings
postgresql://username:password@your-instance.region.rds.amazonaws.com:5432/mydb3Managed PostgreSQL Services
Services like Heroku Postgres, Neon, and others provide connection strings:
postgresql://user:pass@hostname.provider.com:5432/database?sslmode=requireNote: Many managed services require SSL connections. Add ?sslmode=require to your connection string if needed.
Connect in Agent M
- Open Agent M
- Create a new connection
- Select PostgreSQL as the database type
- Enter a name for your connection
- Paste your connection string
- Click Connect
Common Connection Parameters
| Parameter | Description |
|---|---|
| sslmode | SSL mode (disable, allow, prefer, require, verify-ca, verify-full) |
| connect_timeout | Connection timeout in seconds |
| application_name | Name of the application connecting |
| schema | Default schema to use |
Troubleshooting
Authentication Failed
- Verify username and password are correct
- Check if user has permissions on the specified database
- Ensure URL-encoded special characters in password
Connection Refused
- Check if PostgreSQL is running
- Verify firewall allows port 5432
- Check
pg_hba.confallows connections from your IP
SSL/TLS Issues
- If SSL is required, add
?sslmode=requireto connection string - For self-signed certificates, use
sslmode=requireinstead of verify-full