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

# PostgreSQL

**Steps to complete:**

1. [Run SQL script and create schema for Datafold](https://docs.datafold.com/integrations/databases/postgresql.md#run-sql-script-and-create-schema-for-datafold)
2. [Configure your data connection in Datafold](https://docs.datafold.com/integrations/databases/postgresql.md#configure-in-datafold)
3. For Aurora or RDS, see [Amazon Aurora and RDS](https://docs.datafold.com/integrations/databases/postgresql.md#amazon-aurora-and-rds)

## Run SQL script and create schema for Datafold

To connect to Postgres, you need to create a user with read-only access to all tables in all schemas, write access to Datafold-specific schema for temporary tables:

```Bash theme={null}
/* Datafold utilizes a temporary dataset to materialize scratch work and keep data processing in your warehouse. */

CREATE SCHEMA datafold_tmp;

/* Create a datafold user */

CREATE ROLE datafold WITH LOGIN ENCRYPTED PASSWORD 'SOMESECUREPASSWORD';

/* Give the datafold role write access to the temporary schema */

GRANT ALL ON SCHEMA datafold_tmp TO datafold;

/* Make sure that the postgres user has read permissions on the tables */

GRANT USAGE ON SCHEMA <myschema> TO datafold;
GRANT SELECT ON ALL TABLES IN SCHEMA <myschema> TO datafold;

```

Datafold utilizes a temporary schema, named `datafold_tmp` in the above script, to materialize scratch work and keep data processing in your warehouse.

## Configure in Datafold

| Field Name | Description |
| - | - |
| Connection name | A name given to the data connection within Datafold |
| Host | The hostname address for your database |
| Port | Postgres connection port; default value is 5432 |
| Username | The user role created in our SQL script, named datafold |
| Password | The password created in our SQL script |
| Database | The name of the Postgres database you want to connect to |
| Schema path for temporary tables | `<database_name>.datafold_tmp`: the database plus the schema created in our SQL script |

Click **Save**. Your data connection is ready!

## Amazon Aurora and RDS

For Amazon Aurora PostgreSQL or Amazon RDS for PostgreSQL, choose **Amazon PostgreSQL Aurora** or **Amazon PostgreSQL RDS** as the connection type. Run the same [SQL script](#run-sql-script-and-create-schema-for-datafold) and fill in the same fields as above.

These connection types also show a few extra fields:

| Field Name | Description |
| - | - |
| Keep Alive timeout in seconds | Optional. Sends TCP keepalives on idle connections; leave empty to disable |
| Role | Optional. Datafold runs `SET ROLE` with this role (case sensitive) before each query |
| AWS Access Key, AWS Secret, AWS Region, Cloudwatch Postgres Log Group | Optional. Leave them empty: data diffs don't use them |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.