You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/unify/data-graph/setup-guides/snowflake-setup.md
+31-36Lines changed: 31 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -13,18 +13,20 @@ On this page, you'll learn how to connect your Snowflake data warehouse to Segme
13
13
14
14
## Snowflake credentials
15
15
16
-
Log in to Snowflake with admin privileges to provide the Data Graph with the necessary permissions below.
16
+
Segment assumes that you already have a warehouse that includes the datasets you'd like to use for the Data Graph. Log in to Snowflake with admin privileges to provide the Data Graph with the necessary permissions below.
17
17
18
-
## Step 1: Create Segment user and internal database for the Data Graph
18
+
## Step 1: Create a user and internal database for Segment to store checkpoint tables
19
19
20
-
Segment recommends setting up a new Snowflake user and only giving this user permission to access the required databases and schemas. Run the SQL code block below in your SQL worksheet in Snowflake to execute the following tasks:
20
+
Segment recommends setting up a new Snowflake user and only giving this user permissions to access the required databases and schemas. Run the SQL code block below in your SQL worksheet in Snowflake to execute the following tasks:
21
21
22
22
- 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.
23
23
- Grant the Segment user access to the warehouse of your choice. If you'd like to create a new warehouse, uncomment the SQL below.
24
-
-Create a new database for the Data Graph. **Segment requires write access to this database in order to create a schema for internal bookkeeping and to store checkpoint tables for the queries that are executed. Therefore, Segment recommends creating a new empty database for this purpose.** This is also the database you'll be required to specify for the "Database Name" when connecting Snowflake with the Segment app.
24
+
-**Segment requires write access to this database in order to create a schema for internal bookkeeping and to store checkpoint tables for the queries that are executed. Therefore, Segment recommends creating a new database for this purpose.** This is also the database you'll be required to specify for the "Database Name" when connecting Snowflake with the Segment app.
25
25
26
26
> info ""
27
-
> The variables specified at the top of the code block with the `SET` command are placeholders and should be updated.
27
+
> Segment recommends creating a new database for the Data Graph.
28
+
> 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-schema)to update user access for the Segment Reverse ETL schema.
29
+
28
30
29
31
```SQL
30
32
-- ********** SET UP THE FOLLOWING WAREHOUSE PERMISSIONS **********
@@ -78,9 +80,9 @@ GRANT CREATE SCHEMA ON DATABASE identifier($segment_connection_db) TO ROLE iden
78
80
79
81
```
80
82
81
-
## Step 2: Grant read-only access to other databases for the Data Graph
83
+
## Step 2: Grant read-only access to additional databases for the Data Graph
82
84
83
-
Next, give the Segment role **read-only** access to all the other databases you want to use for Data Graph including the Profiles Sync database. Repeat the SQL query below for **each** database you want to use for the Data Graph.
85
+
Next, give the Segment role **read-only** access to additional databases you want to use for Data Graph including the Profiles Sync database. Repeat the SQL query below for **each** database you want to use for the Data Graph.
84
86
85
87
```SQL
86
88
@@ -103,7 +105,7 @@ GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN DATABASE identifier($linked_read_on
## (Optional) Step 3: Restrict read-only access to schemas
107
109
108
110
If you want to restrict access to specific [Snowflake schemas and tables](https://docs.snowflake.com/en/user-guide/security-access-control-privileges#table-privileges), then run the following commands:
109
111
@@ -127,24 +129,7 @@ GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN SCHEMA identifier($linked_read_only
127
129
128
130
```
129
131
130
-
## (If applicable) Step 4: Update user acccess for Segment Reverse ETL schema
131
-
132
-
> warning ""
133
-
> This is only applicable if you choose to use an existing database as the Segment connection database that has also been used for [Segment Reverse ETL](/docs/connections/reverse-etl/).
134
-
135
-
If Segment Reverse ETL has ever run in the database you are configuring as the Segment connection database, a Segment-managed schema is already created and you need to provide the new Segment user access to the existing schema. 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` schema.
136
-
137
-
```SQL
138
-
-- 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.
139
-
140
-
SET retl_schema = concat($segment_connection_db,'.__segment_reverse_etl');
141
-
GRANT USAGE ON SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
142
-
GRANT CREATE TABLE ON SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
143
-
GRANTSELECT,INSERT,UPDATE,DELETEON ALL TABLES IN SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
144
-
145
-
```
146
-
147
-
## Step 5: Confirm permissions
132
+
## Step 4: Confirm permissions
148
133
149
134
To verify you have set up the right permissions for a specific table, log in with the username and password you created for `SEGMENT_CONNECTION_USERNAME` 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.
150
135
@@ -159,22 +144,32 @@ SHOW SCHEMAS;
159
144
SELECT*FROM identifier($table_name) LIMIT10;
160
145
161
146
```
162
-
## Step 6: Connect your warehouse to the Data Graph
147
+
## Step 5: Connect your warehouse to the Data Graph
163
148
To connect your warehouse to the Data Graph:
164
149
165
150
1. Navigate to **Unify > Data Graph**. This should be a Unify space with Profiles Sync already set up.
166
151
2. Click Connect warehouse.
167
152
3. Select Snowflake as your warehouse type.
168
-
4. Enter your warehouse credentials. Segment requires the following settings to connect to your Snowflake warehouse.
169
-
<imgsrc="/docs/unify/images/snowflake-setup.png"alt="Connect Snowflake to Data Graph"width="5888"/>
170
-
171
-
-**Account ID**: The Snowflake account ID that uniquely identifies your organization account.
172
-
-**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_connection_db` in the script below.
173
-
-**Warehouse**: The [warehouse](https://docs.snowflake.com/en/user-guide/warehouses){:target="_blank”} in your Snowflake account that you want to use for Segment to run the SQL queries. This warehouse is referred to as `segment_connection_warehouse` in the script below.
174
-
-**Username**: The Snowflake user that Segment uses to run SQL in your warehouse. This user is referred to as `segment_connection_username` in the script below.
153
+
4. Enter your warehouse credentials. Segment requires the following settings to connect to your Snowflake warehouse:
154
+
-**Account ID**: The Snowflake account ID that uniquely identifies your organization account
155
+
-**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_connection_db` in the script below
156
+
-**Warehouse**: The [warehouse](https://docs.snowflake.com/en/user-guide/warehouses){:target="_blank”} in your Snowflake account that you want to use for Segment to run the SQL queries. This warehouse is referred to as `segment_connection_warehouse` in the script below
157
+
-**Username**: The Snowflake user that Segment uses to run SQL in your warehouse. This user is referred to as `segment_connection_username` in the script below
175
158
-**Authentication**: There are 2 supported authentication methods:
176
-
-**Key Pair**: This is the recommended method of authentication. You would need to first create the user and assign it a key pair following the instructions in the [Snowflake docs](https://docs.snowflake.com/en/user-guide/key-pair-auth). Then, follow the Segment docs above to set up Snowflake permissions and set the `segment_connections_username` variable in the SQL script to the user you just created.
177
-
-**Password**: The password of the user above. This password is referred to as `segment_connection_password` in the script below.
159
+
-**Key Pair**: This is the recommended method of authentication. You would need to first create the user and assign it a key pair following the instructions in the [Snowflake docs](https://docs.snowflake.com/en/user-guide/key-pair-auth). Then, follow the Segment docs above to set up Snowflake permissions and set the `segment_connections_username` variable in the SQL script to the user you just created
160
+
-**Password**: The password of the user above. This password is referred to as `segment_connection_password` in the script below
178
161
179
162
5. Test your connection, then click Save.
180
163
164
+
## Update user acccess for Segment Reverse ETL schema
165
+
If Segment Reverse ETL has ever run in the database you are configuring as the Segment connection database, a Segment-managed schema is already created and you need to provide the new Segment user access to the existing schema. 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` schema.
166
+
167
+
```SQL
168
+
-- 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.
169
+
170
+
SET retl_schema = concat($segment_connection_db,'.__segment_reverse_etl');
171
+
GRANT USAGE ON SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
172
+
GRANT CREATE TABLE ON SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
173
+
GRANTSELECT,INSERT,UPDATE,DELETEON ALL TABLES IN SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
0 commit comments