# How to Set up RDS PostgreSQL Destination in Daton

## Prerequisites <a href="#chap_gettingstarted.prerequisites.mysql" id="chap_gettingstarted.prerequisites.mysql"></a>

Before you get started, ensure you have the following:

* Active Daton and AWS account
* Administrative user for your AWS account to create or configure a Daton-specific RDS PostgreSQL database

## Task 1: Configure a VPC security connection for Amazon RDS for PostgreSQL

1. Log in to your [RDS dashboard](https://console.aws.amazon.com/rds/home).
2. On the VPC dashboard, choose **Create VPC**.
3. For Resources to create, choose **VPC and more** and perform the following.

   1. Name the VPC.&#x20;
   2. Provide the details according to custom requirements and set the rest to default.

      *You can now visualize the relationships between the VPC resources you've configured.*
   3. When you are finished configuring your VPC, choose Create VPC.

   <figure><img src="/files/BdJ8ihOEmDPIb2b4Swsp" alt="" width="375"><figcaption></figcaption></figure>

   <figure><img src="/files/TZtdkvehIO8SZzkWvTFW" alt=""><figcaption></figcaption></figure>
4. Your VPC connection is set.&#x20;

   <figure><img src="/files/uTfJLmD3HTqZxz7cB6ii" alt=""><figcaption></figcaption></figure>

## Task 2: Create and Connect to an RDS for PostgreSQL Database Instance&#x20;

1. [Create a Subnet group for the database](#create-a-subnet-group-for-the-database.)
2. [Create a PostgreSQL Database ](#create-a-mysql-database)
3. [Connect to an EC2 Instance ](#connect-to-an-ec2-instance)
4. [Connect to the Database](#connect-to-the-database)

### Create a Subnet group for the database

1. Navigate to the **RDS** in the Amazon Console.
2. Navigate to the **Subnet groups** section and click **Create DB subnet group**.

   <figure><img src="/files/9323DVA4ZpipiDRe8Kly" alt=""><figcaption></figcaption></figure>
3. On the DB subnet creation page, perform the following:
   * Provide your Subnet group **name** and **description.**

     <figure><img src="/files/zJqeXvJsIas2RlHaVDhz" alt=""><figcaption></figcaption></figure>
   * Select the above-created **VPC identifier.**

     <figure><img src="/files/r6ugKcOjXKgXVGZ0vMx4" alt=""><figcaption></figcaption></figure>
   * Add **Availability zones** and **Subnets,** click **Create**\
     When choosing the Subnets, please ensure to exclusively select the private subnets.

     <figure><img src="/files/svnswwO0u0EAvzfqKoul" alt=""><figcaption></figcaption></figure>
4. A Subnet group has been created.&#x20;

   <figure><img src="/files/zJp1VaQe4OepUUWvbS4N" alt=""><figcaption></figcaption></figure>

### Create a PostgreSQL Database&#x20;

1. In the Amazon RDS navigation pane, choose **Databases**.
2. Choose **Create database** and perform the following:
   1. Select the Engine type as **PostgreSQL** and the Template as **Free tier**.&#x20;

      <figure><img src="/files/9NtUfDBlDMmsVIBdjMd6" alt=""><figcaption></figcaption></figure>
   2. Provide a **Name** in the DB instance identifier, a **Master username,** and create a **Master Password.**

      <figure><img src="/files/iTUf8xNLSCRXxpSAch9V" alt=""><figcaption></figcaption></figure>
   3. In the Instance configuration section, set Burstable classes to **db.t3.micro.**\
      This can be configured as per your specific requirements.

      <figure><img src="/files/L7Xf9hJ9cTe2rxc8ftmI" alt=""><figcaption></figcaption></figure>
   4. In the Storage section, select the fields as per requirement.\
      It is recommended to set the Storage Type to **General Purpose SSD (gp2).**

      <figure><img src="/files/ruzx9dakzwm0ULzYavVE" alt=""><figcaption></figcaption></figure>
   5. In the Connectivity section,&#x20;

      1. Select **Don't connect to an EC2 compute resource**
      2. Select the above-created VPC and DB subnet groups
      3. Set the Public access to **No**
      4. Create a new **VPC security group** for firewall purposes, Name it, and Select an Availability Zone according to your preferences.
      5. Check the **Create an RDS Proxy** checkbox.

      Keep the rest as default or customize according to your requirements.

      <figure><img src="/files/TJqdJ1vUfqCv0vVwpNbh" alt=""><figcaption></figcaption></figure>
   6. Select your **Database Authentication** method, **Monitoring** preferences, and **Additional Configuration** as per your requirements.

      <figure><img src="/files/UtzXjjzT9fMNgwELeUHI" alt=""><figcaption></figcaption></figure>
3. Now check your **Estimated Monthly cost** and click on **Create Database**.\
   A new Database will be successfully created.

Please note that you can customize the database according to your specific requirements. To know more follow the link, [Creating an Amazon RDS DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html).&#x20;

### Connect to an EC2 Instance&#x20;

1. [Launch an EC2 Instance](#create-an-ec2-instance)
2. [Add the EC2 Subnet group to your Database Subnet group](#add-the-ec2-subnet-group-to-your-database-subnet-group)

#### Launch an EC2 Instance&#x20;

1. On the AWS Management Console, go to the Amazon [EC2 console](https://console.aws.amazon.com/ec2/home).
2. Choose EC2 Dashboard, and then choose Launch instance.

   <figure><img src="/files/IzJHtSFbkB7EaJw3w51R" alt="" width="375"><figcaption></figcaption></figure>
3. Provide a Name to the EC2 instance.

   <figure><img src="/files/Nd9fS8vmzrkOJBeemPxv" alt=""><figcaption></figcaption></figure>
4. Under Application and OS Images (Amazon Machine Image), choose an AMI of your choice.

   <figure><img src="/files/yU2hKB7GmLTacfOWYl99" alt=""><figcaption></figcaption></figure>
5. Select the **t2.micro** option under the Instance type.
6. For the Key pair (login), you have two options. If you already have a key pair, just pick its name. If you want a new key pair, click on Create new key pair. Then, follow the steps in the Create key pair window to make the new key pair.

   <figure><img src="/files/mGbYd18K9bpCjjTx3RbB" alt=""><figcaption></figcaption></figure>

   For more information about creating a new key pair, see [Create a key pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html#create-a-key-pair) in the Amazon EC2 User Guide.
7. In the Network settings section, configure these values while leaving the rest at their default:
   1. Select the previously created **VPC**.
   2. Select one of its **Public Subnet**s.
   3. Set Auto-assign public IP to **Enable**.
   4. Create a **Firewall security group** and Name it.

      <figure><img src="/files/ZGgIUFPKVRDBJ8K7TOGk" alt=""><figcaption></figcaption></figure>
8. Now check the settings of the EC2 instance for configuration or keep them as default and click on **Launch**.\
   A note saying the Instance is successfully launched will appear.\
   \
   This is how your EC2 instance would look like:&#x20;

   <figure><img src="/files/2TXf4JxudhE7J7tO7Uzz" alt=""><figcaption></figcaption></figure>

#### Add the EC2 Subnet group to your Database Subnet group

Here we edit the inbound subnet groups to connect the EC2 instance with the Database. This step creates a communication tunnel between the EC2 instance and the Database.

1. In the Amazon RDS dashboard, choose the above-created database instance and click on the **VPC security groups** URL under the **Security** section.

   <figure><img src="/files/Fzw7v9yvdg9OmEhZEQZF" alt=""><figcaption></figcaption></figure>
2. You will be redirected to the Security Groups page of the dedicated Database instance. Find the **Edit inbound rules** button and click on it.

   <figure><img src="/files/WCmq5m9vpSW7rP3G6ICs" alt=""><figcaption></figcaption></figure>
3. On the edit page, perform the following:

   1. **Add rule.** Under the Type dropdown, select **PostgreSQL** and select the source as the security groups corresponding to the EC2 instance.
   2. Add another rule. Here, select the Port range as 3306 and add the IP address accordingly.&#x20;

   <figure><img src="/files/ln1oAaAuuGlS7dVIPYsI" alt=""><figcaption></figcaption></figure>

### Connect to the Database

1. Launch a Database Management tool of your choice.&#x20;

2. Create a new PostgreSQL Database connection.

3. In the connection settings:
   1. Provide the **Endpoint** of the above-created Database Instance.\
      You may find the endpoint in the following location:&#x20;

      <figure><img src="/files/Tl9CJAi2oqH1QWF78jCv" alt=""><figcaption></figcaption></figure>
   2. Provide the Master Username and Password of the Database instance.

4. In the SSH tunneling section:
   1. Insert the **Public IPv4 DNS** of the EC2 instance.\
      You may find the Public IPv4 DNS of the EC2 instance in the following location:&#x20;

      <figure><img src="/files/elsA3jdCU3Y2MTwv2QBR" alt=""><figcaption></figcaption></figure>
   2. Provide the **Key Pair** used while Launching the EC2 Instance. Remember that, this Key pair is supposedly a .pem file.
   3. Test the SSH connection.

5. Save the Database by clicking on the **Finish** button.\
   Your RDS PostgreSQL Database is successfully configured.

> Note that, you can query in your now created database to create Schemas and Tables as per your requirement.&#x20;

## Task 3: Integrate Amazon RDS for PostgreSQL Database Instance with Daton

1. Log in to your [Daton account](https://daton.sarasanalytics.com/u/integrations-list) and search for RDS PostgreSQL in the list of Destinations, then click **Configure**.
2. Enter the Integration Name and click **Next**:&#x20;

   <figure><img src="/files/F6RG13djz6Nho5Db7cwj" alt=""><figcaption></figcaption></figure>
3. Enter the following credentials to configure your warehouse:

   <figure><img src="/files/vR22oAR14fQJ133taKrN" alt=""><figcaption></figcaption></figure>

   1. **RDS PostgreSQL JDBC URL** in the format: **jdbc:postgresql://AmazonRDSPostgreSQL\_Database\_Endpoint:3306/your\_db\_name**
   2. RDS PostgreSQL Master **Username** and **Password**
   3. Set Use Tunnel to **SSH** and provide Proxy Host. \
      Proxy Host is your **Public IPv4 DNS** that can be found in details of the EC2 instance in consideration.
   4. Set the Proxy Port to **22** and the Proxy user to **ec2-user**(Default). You may also create a separate user in the EC2 instance.
4. Select the Schema of your choice.&#x20;

   <figure><img src="/files/FuyL0xoZs7N5djEvlZ1X" alt=""><figcaption></figcaption></figure>

   Now **Submit.** Your warehouse is configured successfully.

> Note:
>
> 1. You may copy the SSH Key that appears at the bottom of the Setup page and add it to you repository for secure Authentication.
> 2. You can query in your created database to create additional Schemas and Tables as per your requirement.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://daton-sarasanalytics.gitbook.io/daton/integrations/destinations/amazon-rds-postgresql/how-to-set-up-rds-postgresql-destination-in-daton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
