> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elementary-data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres

<Tabs>
  <Tab title="Elementary Cloud">
    This guide contains the necessary steps to connect a Postgres environment to your Elementary account.

    ### Create a user for Elementary cloud

    On your dbt project, run:

    ```bash theme={null}
    ## Print the query you should run to generate a user
    dbt run-operation create_elementary_user
    ```

    This command will generate a query to create a user with the necessary permissions. Run this query on your data warehouse with **admin permissions** to create the user.

    #### Permissions and security

    Elementary Cloud doesn't require read permissions to your tables and schemas, but only the following:

    * Read-only access to the Elementary schema.
    * Access to read metadata in `INFORMATION_SCHEMA` (table metadata and query history), related to the tables in your dbt project.

    It is recommended to create a user using the instructions specified above to avoid granting excess privileges.
    For more details, refer to [security and privacy](/cloud/general/security-and-privacy).

    ### Fill the connection form

    Provide the following fields:

    * **Host**: The hostname of your Postgres account to connect to. This can either be a hostname or an IP address.
    * **Port**: The port of your Postgres account to connect to. This is usually `5432`.
    * **Database name**: The name of the database where your Elementary schema exist. e.g. `analytics`.
    * **Elementary schema**: The name of your Elementary schema. Usually `[schema name]_elementary`.
    * **User**: The name of the for Elementary user.
    * **Password**: The password associated with the provided user.

    ### Add the Elementary IP to allowlist

    Elementary IP for allowlist: `3.126.156.226`

    ### Connect via SSH tunnel

    Elementary supports connecting via SSH or reverse SSH tunnel. Reach out to our team for details and support in this deployment.
  </Tab>

  <Tab title="Elementary CLI">
    ### Postgres connection profile

    After installing Elementary's dbt package upon running `dbt deps`,
    you can generate Elementary's profile for usage with `edr` by running the following command within your project:

    ```shell theme={null}
    dbt run-operation elementary.generate_elementary_cli_profile
    ```

    The command will print to the terminal a partially filled template of the profile that's needed for `edr` to work.
    [Fill in the missing authentication fields](https://docs.getdbt.com/reference/warehouse-setups/postgres-setup#profile-configuration)
    in the output and copy it to `~/.dbt/profiles.yml`.

    ```yml Postgres theme={null}
    ## POSTGRES ##
    ## By default, edr expects the profile name 'elementary'.      ##
    ## Configure the database and schema of elementary models.     ##
    ## Check where 'elementary_test_results' is to find it.        ##

    elementary:
      outputs:
        default:
          type: postgres
          host: [hostname]
          user: [username]
          password: [password]
          port: [port]
          dbname: [database name]
          schema: [schema name] # elementary schema, usually [schema name]_elementary
          threads: [1 or more]
          keepalives_idle: 0 # default 0 seconds
          connect_timeout: 10 # default 10 seconds
          # search_path: public # optional, not recommended
          # role: [optional, set the role dbt assumes when executing queries]
          # sslmode: [optional, set the sslmode used to connect to the database]
    ```

    We support the same format and connection methods (user password, key pair authentication, SSO) as dbt. Please refer to
    dbt's documentation of [Postgres profile](https://docs.getdbt.com/reference/warehouse-setups/postgres-setup) for
    further details.
  </Tab>
</Tabs>

### Have a question?

We are available
on [Slack](https://elementary-data.com/community), reach out
for any kind of help!
