> For the complete documentation index, see [llms.txt](https://lightup.gitbook.io/user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lightup.gitbook.io/user-guide/manage-datasources/connect-to-postgres.md).

# Connect to Postgres

Steps to prepare and connect to Postgres

## Lightup account setup: Postgres 14

You'll need a user account that can query data and metadata for all tables you want to monitor. You might already have a user set up that will work, or you might need to create one. Grant the user the sufficient permissions using security roles.&#x20;

You can run the following DDL to create the user account; just substitute a password for *\<strong\_password\_here>*:

```
CREATE USER lightup WITH LOGIN BYPASSRLS ENCRYPTED PASSWORD '<strong_password_here>' IN ROLE pg_read_all_data;
```

### Postgres 11-13

Run the following DDL to create the user account; just substitute a password for *\*\*redacted\*\**:

```sql
cdb=> CREATE ROLE readaccess;
CREATE ROLE
cdb=> GRANT CONNECT ON DATABASE cdb TO readaccess;
GRANT
cdb=> GRANT USAGE ON SCHEMA testdata TO readaccess;
GRANT
cdb=> GRANT SELECT ON ALL TABLES IN SCHEMA testdata TO readaccess;
GRANT
cdb=> CREATE USER lightup WITH LOGIN BYPASSRLS ENCRYPTED PASSWORD '**redacted**';
CREATE ROLE
cdb=> GRANT readaccess TO lightup;
GRANT ROLE
```

### Query governance

* You can [enable **Query Timeout**](broken://pages/Ppw9BrPQMUl9JWFLALbT#set-query-governance-for-a-datasource). Enabling it will mean that any query that runs for more than one hour will fail.

## Connector settings

* **Host Name** - The hostname for the datasource (check the browser address bar; you want the string between **//** and **/**). Example: `https://`**`host.na.me`**`/`
* **Database Name** - The name of the database you're connecting to.
* **Username** - Enter ***lightup***.
* **Password** - The username account's password.
