Menu
Amazon Relational Database Service
User Guide (API Version 2014-10-31)

Connecting to a DB Instance Running the PostgreSQL Database Engine

After Amazon RDS provisions your DB instance, you can use any standard SQL client application to connect to the instance. To list the details of an Amazon RDS DB instance, you can use the AWS Management Console, the AWS CLI describe-db-instances command, or the Amazon RDS API DescribeDBInstances action. You need the following information to connect:

  • The host or host name for the DB instance, for example:

    myinstance.123456789012.us-east-1.rds.amazonaws.com
  • The port on which the DB instance is listening. For example, the default PostgreSQL port is 5432.

  • The user name and password for the DB instance.

Following are two ways to connect to a PostgreSQL DB instance. The first example uses pgAdmin, a popular open-source administration and development tool for PostgreSQL. The second example uses psql, a command line utility that is part of a PostgreSQL installation.

Using pgAdmin to Connect to a PostgreSQL DB Instance

You can use the open-source tool pgAdmin to connect to a PostgreSQL DB instance.

To connect to a PostgreSQL DB instance using pgAdmin

  1. Install pgAdmin from http://www.pgadmin.org/. You can download and use pgAdmin without having a local instance of PostgreSQL on your client computer.

  2. Launch the pgAdmin application on your client computer.

  3. On the Dashboard tab, choose Add New Server.

  4. In the Create - Server dialog box, type a name on the General tab to identify the server in pgAdmin.

  5. On the Connection tab, type the following information from your DB instance:

    • For Host, type the endpoint, for example mypostgresql.c6c8dntfzzhgv0.us-east-2.rds.amazonaws.com.

    • For Port, type the assigned port.

    • For Username, type the user name that you entered when you created the DB instance.

    • For Password, type the password that you entered when you created the DB instance.

  6. Choose Save.

    If you have any problems connecting, see Troubleshooting Connection Issues.

  7. To access a database in the pgAdmin browser, expand Servers, the DB instance, and Databases. Choose the DB instance's database name.

  8. To open a panel where you can enter SQL commands, choose Tools, Query Tool.

Using psql to Connect to a PostgreSQL DB Instance

You can use a local instance of the psql command line utility to connect to a PostgreSQL DB instance. You need either PostgreSQL or the psql client installed on your client computer. To connect to your PostgreSQL DB instance using psql, you need to provide host information and access credentials.

Use one of the following formats to connect to a PostgreSQL DB instance on Amazon RDS. When you connect, you're prompted for a password. For batch jobs or scripts, use the --no-password option.

For Unix, use the following format.

psql \ --host=<DB instance endpoint> \ --port=<port> \ --username=<master user name> \ --password \ --dbname=<database name>

For Windows, use the following format.

psql ^ --host=<DB instance endpoint> ^ --port=<port> ^ --username=<master user name> ^ --password ^ --dbname=<database name>

For example, the following command connects to a database called mypgdb on a PostgreSQL DB instance called mypostgresql using fictitious credentials.

psql --host=mypostgresql.c6c8mwvfdgv0.us-west-2.rds.amazonaws.com --port=5432 --username=awsuser --password --dbname=mypgdb

Troubleshooting Connection Issues

If you can't connect to the DB instance, the most common error is Could not connect to server: Connection timed out. If you receive this error, do the following:

  • Check that the host name used is the DB instance endpoint and that the port number used is correct.

  • Make sure that the DB instance's public accessibility is set to Yes.

  • Check that the security group assigned to the DB instance has rules to allow access through any firewall your connection might go through. For example, if the DB instance was created using the default port of 5432, your company might have firewall rules blocking connections to that port from company devices.

    To fix this failure, modify the DB instance to use a different port. Also, make sure that the security group applied to the DB instance allows connections to the new port.

  • Check whether the DB instance was created using a security group that doesn't authorize connections from the device or Amazon EC2 instance where the application is running. For the connection to work, the security group you assigned to the DB instance at its creation must allow access to the DB instance. For example, if the DB instance was created in a VPC, it must have a VPC security group that authorizes connections. Alternatively, if the DB instance was created outside of a VPC, it must have a database security group that authorizes those connections.

By far the most common connection problem is with the security group's access rules assigned to the DB instance. If you used the default DB security group when you created the DB instance, the security group likely didn't have access rules that allow you to access the instance. For more information about Amazon RDS security groups, see Amazon RDS Security Groups.