Connecting to a DB instance running the PostgreSQL database engine (original) (raw)

After Amazon RDS provisions your DB instance, you can use any standard SQL client application to connect to the instance. Before you can connect, the DB instance must be available and accessible. Whether you can connect to the instance from outside the VPC depends on how you created the Amazon RDS DB instance:

To check whether your DB instance is public or private, use the AWS Management Console to view theConnectivity & security tab for your instance. UnderSecurity, you can find the "Publicly accessible" value, with No for private, Yes for public.

To learn more about different Amazon RDS and Amazon VPC configurations and how they affect accessibility, see Scenarios for accessing a DB instance in a VPC.

Contents

Installing the psql client

To connect to your DB instance from an EC2 instance, you can install a PostgreSQL client on the EC2 instance. To install the latest version of the psql client on Amazon Linux 2023, run the following command:

sudo dnf install postgresql

To install the latest version of the psql client on Amazon Linux 2, run the following command:

sudo yum install -y postgresql

To install the latest version of the psql client on Ubuntu, run the following command:

sudo apt install -y postgresql-client

Finding the connection information for an RDS for PostgreSQL DB instance

If the DB instance is available and accessible, you can connect by providing the following information to the SQL client application:

You can obtain these details by using the AWS Management Console, the AWS CLI describe-db-instances command, or the Amazon RDS API DescribeDBInstances operation.

To find the endpoint, port number, and DB name using the AWS Management Console
  1. Sign in to the AWS Management Console and open the Amazon RDS console athttps://console.aws.amazon.com/rds/.
  2. Open the RDS console and then choose Databases to display a list of your DB instances.
  3. Choose the PostgreSQL DB instance name to display its details.
  4. On the Connectivity & security tab, copy the endpoint. Also, note the port number. You need both the endpoint and the port number to connect to the DB instance.
    Obtain the endpoint from the RDS Console
  5. On the Configuration tab, note the DB name. If you created a database when you created the RDS for PostgreSQL instance, you see the name listed under DB name. If you didn't create a database, the DB name displays a dash (‐).
    Obtain the DB name from the RDS Console

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.