|
2 | 2 | title: Redshift Data Graph Setup
|
3 | 3 | beta: true
|
4 | 4 | plan: unify
|
5 |
| -hidden: true |
6 | 5 | redirect_from:
|
7 | 6 | - '/unify/linked-profiles/setup-guides/redshift-setup'
|
8 | 7 | ---
|
9 | 8 |
|
10 |
| -> info "Linked Audiences is in public beta" |
11 |
| -> Linked Audiences (with Data Graph, Linked Events) is in public beta, and Segment is actively working on this feature. Some functionality may change before it becomes generally available. |
12 |
| -
|
13 | 9 | > info ""
|
14 |
| -> At this time, you can only use Redshift with Linked Events. |
| 10 | +> Redshift for Data Graph is in beta and Segment is actively working on this feature. Some functionality may change before it becomes generally available. This feature is governed by Twilio Segment’s [First Access and Beta Preview Terms](https://www.twilio.com/en-us/legal/tos){:target="_blank"}. |
| 11 | +
|
| 12 | +Set up your Redshift data warehouse to Segment for the [Data Graph](/docs/unify/data-graph/). |
| 13 | + |
| 14 | +## Prerequisite |
15 | 15 |
|
16 |
| -On this page, you'll learn how to connect your Redshift data warehouse to Segment. |
| 16 | +To use Linked Audiences with Redshift, the Data Graph only supports [materialized views](/docs/unify/profiles-sync/tables/#tables-segment-materializes). |
| 17 | + |
| 18 | +If you're setting up Profiles Sync for the first time in the Unify space, go through the setup flow for Selective sync. If Profiles Sync is already set up for your Unify space, follow these steps to configure Profiles Sync for your Unify space: |
| 19 | + |
| 20 | +1. Navigate to **Unify > Profile Sync**. |
| 21 | +2. Select the **Settings** tab and select **Selective sync**. |
| 22 | +3. Select all the tables under **Profile raw tables**. These include, `external_id_mapping_updates`, `id_graph_updates`, `profile_traits_updates`. Linked Audiences require Profile Sync to be configured such that both the Profile raw tables and the Profile materialized tables are synchronized with your Redshift instance. |
| 23 | +4. Select all of the tables under **Profile materialized tables**. These include `profile_merges`, `user_traits`, `user_identifiers`. This allows faster and more cost-efficient Linked Audiences computations in your data warehouse. |
| 24 | +5. Select **Sync all Track Call Tables** under **Track event tables** to enable filtering on event history for Linked Audiences conditions. |
17 | 25 |
|
18 | 26 | ## Getting started
|
19 | 27 |
|
| 28 | +You need to be an AWS Redshift account admin to set up the Segment Redshift connector as well as write permissions for the `__segment_reverse_etl` dataset. |
| 29 | + |
20 | 30 | To get started with Redshift:
|
21 | 31 | 1. Log in to Redshift and select the Redshift cluster you want to connect.
|
22 |
| -2. Follow these [networking instructions](/docs/connections/storage/catalog/redshift/#networking) to configure network and security settings. |
| 32 | +2. Follow the [networking instructions](/docs/connections/storage/catalog/redshift/#networking) to configure network and security settings. |
23 | 33 |
|
24 |
| -## Create a new role and user |
| 34 | +## Step 1: Roles and permissions |
| 35 | +Segment recommends you to create a new Redshift user and role with only the required permissions. |
25 | 36 |
|
26 |
| -Run the SQL commands below to create a role (`segment_entities`) and user (`segment_entities_user`). |
| 37 | +Create a new role and user for the Segment Data Graph. This new role will only have access to the datasets you provide access to for the Data Graph. Run the SQL commands in your Redshift cluster: |
27 | 38 |
|
28 |
| -```sql |
29 |
| --- create role |
30 |
| -CREATE ROLE segment_entities; |
| 39 | + ```sql |
| 40 | + -- Create a user with role for the Data Graph |
| 41 | + CREATE ROLE SEGMENT_LINKED_ROLE; |
| 42 | + CREATE USER SEGMENT_LINKED_USER PASSWORD "your_password"; |
| 43 | + GRANT ROLE SEGMENT_LINKED_ROLE TO SEGMENT_LINKED_USER; |
| 44 | + ``` |
| 45 | + |
| 46 | +## Step 2: Create a database for Segment to store checkpoint tables |
| 47 | + |
| 48 | +> info "" |
| 49 | +> Segment recommends you to create a new database for the Data Graph. If you choose to use an existing database that has also been used for [Segment Reverse ETL](/docs/connections/reverse-etl/), you must follow the [additional instructions](#update-user-access-for-segment-reverse-etl-dataset) to update user access for the Segment Reverse ETL schema. |
| 50 | +
|
| 51 | +Provide write access to the database as Segment requires this in order to create a schema for internal bookkeeping and to store checkpoint tables for the queries that are executed. Segment recommends you to create a new database for this purpose. This is also the database you'll be required to specify for the **Database Name** when connecting Redshift with the Segment app. |
31 | 52 |
|
32 |
| --- allow the role to create new schemas on specified database. (This is the name you chose when provisioning your cluster) |
33 |
| -GRANT CREATE ON DATABASE "<enter database name here>" TO ROLE segment_entities; |
| 53 | +Run the following SQL commands in your Redshift cluster: |
34 | 54 |
|
35 |
| --- create a user named "segment_entities_user" that Segment will use when connecting to your Redshift cluster. |
36 |
| -CREATE USER segment_entities_user PASSWORD '<enter password here>'; |
| 55 | +```sql |
| 56 | +-- Create and Grant access to a Segment internal DB used for bookkeeping |
37 | 57 |
|
38 |
| --- grant role permissions to the user |
39 |
| -GRANT ROLE segment_entities TO segment_entities_user; |
| 58 | +CREATE DATABASE SEGMENT_LINKED_PROFILES_DB; |
| 59 | +GRANT CREATE ON DATABASE SEGMENT_LINKED_PROFILES_DB TO ROLE SEGMENT_LINKED_ROLE; |
40 | 60 | ```
|
41 | 61 |
|
42 |
| -## Grant access to schemas and tables |
| 62 | +## Step 3: Grant read-only access for the Data Graph |
| 63 | +Grant the Segment role read-only access to additional schemas you want to use for the Data Graph including the Profiles Sync database. |
43 | 64 |
|
44 |
| -You'll need to grant access to schemas and tables that you'd like to enrich with. This allows Segment to list schemas, tables, and columns, as well as create entities with data extracted and ingested to Segment. |
| 65 | +To locate the Profile Sync database, navigate to **Unify > Profiles Sync > Settings > Connection Settings**. You will see the database and schema name. |
45 | 66 |
|
46 | 67 | ### Schemas
|
| 68 | +Grant schema permissions based on customer need. See Amazon’s docs to view [schema permissions](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html){:target="_blank"} and [example commands](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT-examples.html){:target="_blank"} that you can use to grant permissions. Repeat the following SQL query for each schema you want to use for the Data Graph. |
47 | 69 |
|
48 |
| -Grant schema permissions based on customer need. Visit Amazon's docs to view [schema permissions](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html){:target="_blank"} and [example commands](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT-examples.html){:target="_blank"} that you can use to grant permissions. |
| 70 | +```sql |
| 71 | +-- ********** REPEAT THE SQL QUERY BELOW FOR EACH SCHEMA YOU WANT TO USE FOR THE DATA GRAPH ********** |
49 | 72 |
|
50 |
| -```ts |
51 |
| --- view specific schemas in database |
52 |
| -GRANT USAGE ON SCHEMA <schema-name> TO ROLE segment_entities; |
| 73 | +GRANT USAGE ON SCHEMA "the_schema_name" TO ROLE SEGMENT_LINKED_ROLE; |
53 | 74 | ```
|
54 | 75 |
|
55 |
| -### Tables |
| 76 | +### Table |
| 77 | +Grant table permissions based on your needs. Learn more about [Amazon’s table permissions](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html){:target="_blank"}. |
| 78 | + |
| 79 | +Table permissions can either be handled in bulk: |
| 80 | + |
| 81 | +```sql |
| 82 | +-- query data from all tables in a schema |
| 83 | +GRANT SELECT ON ALL TABLES IN SCHEMA "the_schema_name" TO ROLE SEGMENT_LINKED_ROLE; |
| 84 | +``` |
56 | 85 |
|
57 |
| -Grant table permissions based on customer need. Learn more about Amazon's [table permissions](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html){:target="_blank"}. |
| 86 | +Or in a more granular fashion if needed: |
58 | 87 |
|
59 |
| -```ts |
| 88 | +```sql |
60 | 89 | -- query data from a specific table in a schema
|
61 |
| -GRANT SELECT ON TABLE <schema-name>.<table-name> TO ROLE segment_entities; |
| 90 | +GRANT SELECT ON TABLE <schema-name>.<table-name> TO ROLE segment_linked_role; |
62 | 91 | ```
|
63 | 92 |
|
64 |
| -### RETL table permissions |
| 93 | +## Step 4: Validate permissions |
| 94 | +To verify you have set up the right permissions for a specific table, log in with the username and password you created for `SEGMENT_LINKED_USER` and run the following command to verify the role you created has the correct permissions. If this command succeeds, you should be able to view the respective table. |
65 | 95 |
|
66 |
| -If you used RETL in your database, you'll need to add the following [table permissions](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html){:target="_blank"}: |
| 96 | +```sql |
| 97 | +SHOW SCHEMAS FROM DATABASE "THE_READ_ONLY_DB"; |
| 98 | +SELECT * FROM "THE_READ_ONLY_DB.A_SCHEMA.SOME_TABLE" LIMIT 10; |
| 99 | +``` |
67 | 100 |
|
68 |
| -```ts |
69 |
| -GRANT USAGE, CREATE ON SCHEMA __segment_reverse_etl TO ROLE segment_entities; |
| 101 | +## Step 5: Connect your warehouse to Segment |
| 102 | +To connect your warehouse to Segment: |
| 103 | +1. Navigate to **Unify > Data Graph**. This should be a Unify space with Profiles Sync already set up. |
| 104 | +2. Click **Connect warehouse**. |
| 105 | +3. Select **Redshift** as your warehouse type. |
| 106 | +4. Enter your warehouse credentials. Segment requires the following settings to connect to your Redshift warehouse: |
| 107 | + * **Host Name:** The Redshift URL |
| 108 | + * **Port:** The Redshift connection port |
| 109 | + * **Database:** The only database that Segment requires write access to in order to create tables for internal bookkeeping. This database is referred to as `segment_linked_profiles_db` in the SQL above. |
| 110 | + * **Username:** The Redshift user that Segment uses to run SQL in your warehouse. This user is referred to as `segment_linked_user` in the SQL above. |
| 111 | + * **Password:** The password of the user above |
| 112 | +5. Test your connection, then click **Save**. |
| 113 | + |
| 114 | +## Update user access for Segment Reverse ETL dataset |
| 115 | +If Segment Reverse ETL ran in the project you are configuring as the Segment connection project, a Segment-managed dataset is already created, and you need to provide the new Segment user access to the existing dataset. Run the following SQL if you run into an error on the Segment app indicating that the user doesn’t have sufficient privileges on an existing `__segment_reverse_etl`: |
| 116 | + |
| 117 | +```sql |
| 118 | +-- If you want to use an existing database that already has Segment Reverse ETL schemas, you’ll need to run some additional steps below to grant the role access to the existing schemas. |
70 | 119 |
|
71 |
| -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA __segment_reverse_etl TO ROLE segment_entities; |
| 120 | +GRANT USAGE, CREATE, DROP ON SCHEMA segment_connection_db.__segment_reverse_etl TO ROLE SEGMENT_LINKED_ROLE; |
| 121 | +GRANT SELECT,INSERT,UPDATE,DELETE,DROP ON ALL TABLES IN SCHEMA segment_connection_db.__segment_reverse_etl TO ROLE SEGMENT_LINKED_ROLE; |
72 | 122 | ```
|
0 commit comments