Guide
How to connect to Amazon RDS for PostgreSQL (and Aurora)
Copy the instance's endpoint and port from the RDS console (Connectivity & security), allow your IP on port 5432 in its security group, then connect with SSL: psql "host=mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com port=5432 dbname=postgres user=postgres sslmode=require". If the instance isn't publicly accessible, go through a bastion or Session Manager. A timeout is a network problem, never a wrong password.
Find the endpoint, port, database and user
In the RDS console, open Databases, choose the instance and look under Connectivity & security: the Endpoint is the host name, next to the Port (5432 unless you changed it). The same tab shows Publicly accessible and the VPC security groups, which you'll need below. From the AWS CLI:
aws rds describe-db-instances --db-instance-identifier mydb \
--query 'DBInstances[0].[Endpoint.Address,Endpoint.Port,PubliclyAccessible]' \
--output textAurora gives a cluster two endpoints. The cluster (writer) endpoint, mycluster.cluster-c1a2b3c4d5e6.us-east-1.rds.amazonaws.com, always points at the primary and is the one to use for writes and schema changes. The reader endpoint, with cluster-ro- in its name, spreads read-only connections over the replicas.
aws rds describe-db-clusters --db-cluster-identifier mycluster \
--query 'DBClusters[0].[Endpoint,ReaderEndpoint,Port]' --output textThe user is the master user name you chose when creating the instance (postgres unless you changed it). The database is the initial database name you gave, or postgres if you left it empty; FATAL: database "mydb" does not exist usually means the instance name was used as the database name. AWS advises against using the master user in applications, so create a user for each app once you're in.
Connect with psql
psql "host=mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com port=5432 dbname=postgres user=postgres sslmode=require"
# or as a URI
psql "postgresql://[email protected]:5432/postgres?sslmode=require"psql asks for the password. Once you're in, check the connection is encrypted:
SELECT ssl, version, cipher FROM pg_stat_ssl WHERE pid = pg_backend_pid();Then \l, \dt and \du work as on any PostgreSQL; see the psql commands cheat sheet. Use a psql at least as new as the server: on macOS, install the libpq client with Homebrew.
SSL: require vs verify-full
RDS for PostgreSQL 15 and later sets rds.force_ssl to 1 by default, so connections without SSL are refused; on 14 and older the default is 0. Aurora PostgreSQL switched the default on in version 17. A refused plain connection looks like this:
FATAL: no pg_hba.conf entry for host "203.0.113.25", user "postgres", database "postgres", SSL off(depending on the version, the line ends in SSL off or no encryption). libpq's default sslmode=prefer tries SSL first, so a plain psql -h … usually works anyway; say require to be sure.
require encrypts but doesn't prove you reached your database. For that, use verify-full, which checks the certificate chain and that the host name matches. RDS certificates are signed by Amazon RDS's own certificate authorities (the default for new instances is rds-ca-rsa2048-g1), so download AWS's bundle and point libpq at it:
mkdir -p ~/.postgresql
curl -o ~/.postgresql/rds-global-bundle.pem \
https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
psql "host=mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com port=5432 dbname=postgres user=postgres \
sslmode=verify-full sslrootcert=$HOME/.postgresql/rds-global-bundle.pem"The global bundle covers every commercial region; per-region bundles are on the same host. Trust only these root certificates, not intermediate or server certificates: RDS rotates server certificates automatically.
Through a tunnel (below) you connect to 127.0.0.1, which doesn't match the name in the certificate, so verify-full fails with a host name mismatch. Use verify-ca there: it still checks that an RDS CA signed the certificate.
Network: public access and security groups
If psql hangs and then reports Connection timed out, the packets aren't reaching the database. Work through AWS's checklist:
- Publicly accessible must be Yes to connect from outside the VPC, and the instance's subnets need a route to an internet gateway. If it is No, use one of the private routes in the next section rather than flipping it.
- The instance's VPC security group needs an inbound rule for TCP on the database port from your address. In the console, Source: My IP fills it in. Avoid
0.0.0.0/0. - Your own network must allow outbound connections to port 5432; some company firewalls don't.
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 \
--protocol tcp --port 5432 --cidr 203.0.113.25/32
# test the port before blaming psql (RDS doesn't answer ping)
nc -zv mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com 5432Private subnets: SSH tunnel or Session Manager
Most production databases are not publicly accessible. To reach one from your Mac, go through something inside the VPC. With an EC2 bastion you can SSH to, forward a local port (the database's security group must allow the bastion):
ssh -N -L 5433:mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com:5432 [email protected]
# in another terminal
psql "host=127.0.0.1 port=5433 dbname=postgres user=postgres sslmode=verify-ca \
sslrootcert=$HOME/.postgresql/rds-global-bundle.pem"Local port 5433 avoids clashing with a PostgreSQL running on your own machine. SSH tunnels explains the options and host key checks.
Without an open SSH port, AWS Systems Manager Session Manager can forward the same way through any managed EC2 instance in the VPC. It needs the Session Manager plugin for the AWS CLI on your Mac and SSM Agent 3.1.1374.0 or later on the instance:
aws ssm start-session --target i-0123456789abcdef0 \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters '{"host":["mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com"],"portNumber":["5432"],"localPortNumber":["5433"]}'IAM database authentication
Instead of a password, RDS can accept a short-lived token signed with your AWS credentials. Turn on IAM database authentication on the instance, give the IAM identity a policy allowing rds-db:connect on arn:aws:rds-db:region:account-id:dbuser:DbiResourceId/db_user (the cluster's DbClusterResourceId on Aurora), and create the database user:
CREATE USER app_iam;
GRANT rds_iam TO app_iam;Then generate a token and use it as the password. SSL is required:
export RDSHOST="mydb.c1a2b3c4d5e6.us-east-1.rds.amazonaws.com"
export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $RDSHOST --port 5432 \
--region us-east-1 --username app_iam)"
psql "host=$RDSHOST port=5432 dbname=postgres user=app_iam sslmode=verify-full \
sslrootcert=$HOME/.postgresql/rds-global-bundle.pem"Things to know: a token is valid for 15 minutes, but only for opening connections; a session that is already open carries on. Generate the token for the real endpoint, not a custom DNS name. Tokens are about 1 KB or longer, and a tool that truncates long passwords will fail. Once a user has rds_iam, it must sign in with a token; its password stops working, and that includes the master user. Failures show up as PAM authentication failed for user: an expired token, a missing rds-db:connect permission, a wrong resource ID in the policy, or IAM authentication not enabled on the instance.
Fix common errors
Connection timed out or Operation timed out. Network, not credentials: security group, public accessibility, route to the internet gateway, or a firewall on your side. Test with nc -zv.
Connection refused. Something answered but nothing listens on that port: the wrong port, or, through a tunnel, a local port the tunnel isn't using. Check nothing else holds the local port (lsof -i :5433).
could not translate host name … to address. A typo in the endpoint, or an instance that has been renamed or deleted.
password authentication failed for user "postgres". Wrong password, wrong user name, or a password whose VALID UNTIL has passed. If the master password is lost, set a new one: aws rds modify-db-instance --db-instance-identifier mydb --master-user-password '…' --apply-immediately.
no pg_hba.conf entry for host …, SSL off. SSL is required; add sslmode=require.
certificate verify failed or server certificate for "…" does not match host name. libpq can't find the RDS CA (pass sslrootcert), or you used verify-full through a tunnel.
PAM authentication failed for user. An IAM login problem; see above.
Connecting from Tablux
Tablux connects to RDS and Aurora PostgreSQL from a Mac, iPhone or iPad with the same details: endpoint as host, port, database, user and password, with Use SSL / TLS on. Its SSL encrypts the connection but does not verify the server certificate, so it is the equivalent of sslmode=require, not verify-full. For an instance in a private subnet, switch on the built-in SSH tunnel and enter your bastion; the database host is then the RDS endpoint as the bastion sees it. Tablux signs in with a user name and password and can't generate IAM tokens; a pasted token would expire after 15 minutes for new connections, so create a password user for it. Mark the connection Production, or read-only, and writes ask first or are refused.
Questions
Why does my connection to RDS PostgreSQL time out?
A timeout means the network path is blocked: the security group has no inbound rule for your IP on port 5432, the instance isn't publicly accessible, its subnet has no route to an internet gateway, or a firewall on your side blocks the port.
What is the default database name on RDS PostgreSQL?
postgres, unless you set an initial database name when creating the instance. The default master user name is also postgres.
Does RDS PostgreSQL require SSL?
On RDS for PostgreSQL 15 and later, yes by default: rds.force_ssl is 1. On 14 and older it is 0 unless you change the parameter group. Aurora PostgreSQL requires SSL by default from version 17.
How long is an RDS IAM authentication token valid?
15 minutes. It is only checked when a connection opens, so sessions that are already connected continue after it expires.
How do I connect to an RDS instance in a private subnet?
Forward a local port through something inside the VPC: an SSH bastion with ssh -L, or AWS Systems Manager Session Manager with the AWS-StartPortForwardingSessionToRemoteHost document. Then connect psql to 127.0.0.1 on the local port.
Updated 2026-11-26