# Postgres

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:

```sql
/* Create schema for Datafold to write temporary tables to.
    This is the only schema where Datafold will modify anything in your environment.*/

CREATE SCHEMA datafold_tmp;

/* Create a datafold user */

CREATE ROLE datafold WITH LOGIN ENCRYPTED PASSWORD 'SOMESECUREPASSWORD';

/* 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;
```

### AWS Aurora Postgres Lineage

This will guide you through setting up Lineage with AWS using CloudWatch. AWS Aurora Serverless is not tied to any (virtual) machine, and therefore it only allows you to send the logs to CloudWatch. In these steps we will:

* **Increase the verbosity of the logging of Postgres;** to make sure that we log the required statements to track lineage
* **Set up an account for fetching the logs from CloudWatch;** we will follow the best practices and create a new account for Datafold, to fetch the logs from CloudWatch.

#### Increased verbosity

Let's say that we have `fokkos-aurora` Postgresql instance in AWS that we want to extract lineage from:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgG8UWtlsEkblxToN5R%2Fimage.png?alt=media\&token=26fa4808-36a6-42b9-964f-3097ff73a756)

First, we need to create a new Parameter group. The database instance runs with the default parameters. If you want to set parameters (such as the logging verbosity), you need to create a new Parameter group. Hit **Parameter Groups** on the menu, and create a new Parameter Group:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgG9-Q-TUag8eZdBfga%2Fimage.png?alt=media\&token=68792138-7263-40db-8d1a-7d9218631248)

Next, we select the `aurora-postgresql10` parameter group family. This depends on the cluster that you're running. For Aurora serverless, this is the appropriate family.,

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgG9_xqqfc0YWsYGBX1%2Fimage.png?alt=media\&token=02426cba-ec2a-4fcc-8882-22d015a989e3)

We want to set the `log_statement` enum field. By default, this isn't set, and we want to set it to mod, meaning that it will log all the DDL statements, plus data-modifying statements:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGBpUyxNhnOLjhrPqV%2Fimage.png?alt=media\&token=b4348585-c537-455a-8ae9-429343a062c7)

After saving the parameter group, we can go back to our database, and select the right DB cluster parameter group:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGC2Lz1DysfdWL4N2v%2Fimage.png?alt=media\&token=6bd6966b-5824-4406-bfdc-68be6fb1020f)

After saving, we're ready to hook up Datafold to CloudWatch.

### Connect Datafold to CloudWatch

Creating a user for Datafold is quite straightforward. It is best to create a new user to isolate the permissions as much as possible. First, we go to IAM an create a new user:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGCqsStq5a6OYrE2va%2Fimage.png?alt=media\&token=c8ad497a-54c7-40aa-8f8c-30e45833672d)

Make sure that the Programmatic Access checkbox has been checked. Next, we'll create a new group:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGD5LYC-5KpXXLEgit%2Fimage.png?alt=media\&token=38e1722d-574b-42ed-a4b3-4480471b798f)

We call this group `CloudWatchLogsReadOnly` and attache the `CloudWatchLogsReadOnlyAccess` policy to it. Next, we select the group:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGDe9Kv6EfJK08hd3e%2Fimage.png?alt=media\&token=449e6847-92b4-481d-8681-42ba41b4aaa9)

When reviewing the user, it should have the freshly created group attached to it:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGDjIJygUXtvQiKHR9%2Fimage.png?alt=media\&token=0554bff4-6958-428f-a1f3-b7245cb7ff07)

Now we have the new access together with the Access key ID and the Secret access key:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGDtZdoSyC4cRLPDZP%2Fimage.png?alt=media\&token=bf75a864-8cb6-4f8a-828d-e97916b67bc8)

Make sure that the credentials are kept secure. Store them somewhere safely (for example, a password manager), because we need them later to store them into Datafold.

Next, go to CloudWatch and lookup the Log group:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGEKufsMAhhMK0OsAX%2Fimage.png?alt=media\&token=ae0e0b30-41b6-4867-9d5d-74709d45996e)

We need to supply the Credentials and the Log group to Datafold:

![](https://987627956-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MW5oouougFyPvHgESLi%2F-MgG6rXMof64i_nssptB%2F-MgGHm0SAotciV9fSwDL%2Fimage.png?alt=media\&token=7b35d4a6-f9f8-436c-b3cd-dadc56c3d77f)

> [IP Whitelisting ->](../../developer/security/network-security)

> After setting permissions in your data source, move on to [Configuration ->](../configuration)
