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/mydb

With authentication:

postgresql://username:password@localhost:5432/mydb

2Cloud 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/mydb

3Managed PostgreSQL Services

Services like Heroku Postgres, Neon, and others provide connection strings:

postgresql://user:pass@hostname.provider.com:5432/database?sslmode=require

Note: Many managed services require SSL connections. Add ?sslmode=require to your connection string if needed.

Connect in Agent M

  1. Open Agent M
  2. Create a new connection
  3. Select PostgreSQL as the database type
  4. Enter a name for your connection
  5. Paste your connection string
  6. Click Connect

Common Connection Parameters

ParameterDescription
sslmodeSSL mode (disable, allow, prefer, require, verify-ca, verify-full)
connect_timeoutConnection timeout in seconds
application_nameName of the application connecting
schemaDefault 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.conf allows connections from your IP

SSL/TLS Issues

  • If SSL is required, add ?sslmode=require to connection string
  • For self-signed certificates, use sslmode=require instead of verify-full

Additional Resources

Next Steps