Skip to content

Commit fc5e3a0

Browse files
authored
Update snowflake-setup.md
1 parent 2defe0b commit fc5e3a0

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

src/unify/data-graph/setup-guides/snowflake-setup.md

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ On this page, you'll learn how to connect your Snowflake data warehouse to Segme
1313

1414
## Snowflake credentials
1515

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.
1717

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
1919

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:
2121

2222
- 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.
2323
- 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.
2525

2626
> 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+
2830

2931
```SQL
3032
-- ********** SET UP THE FOLLOWING WAREHOUSE PERMISSIONS **********
@@ -78,9 +80,9 @@ GRANT CREATE SCHEMA ON DATABASE identifier($segment_connection_db) TO ROLE iden
7880

7981
```
8082

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
8284

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.
8486

8587
``` SQL
8688

@@ -103,7 +105,7 @@ GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN DATABASE identifier($linked_read_on
103105

104106
```
105107

106-
## (Optional) Step 3: Restrict Snowflake schema access
108+
## (Optional) Step 3: Restrict read-only access to schemas
107109

108110
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:
109111

@@ -127,24 +129,7 @@ GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN SCHEMA identifier($linked_read_only
127129

128130
```
129131

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-
GRANT SELECT,INSERT,UPDATE,DELETE ON 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
148133

149134
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.
150135

@@ -159,22 +144,32 @@ SHOW SCHEMAS;
159144
SELECT * FROM identifier($table_name) LIMIT 10;
160145

161146
```
162-
## Step 6: Connect your warehouse to the Data Graph
147+
## Step 5: Connect your warehouse to the Data Graph
163148
To connect your warehouse to the Data Graph:
164149

165150
1. Navigate to **Unify > Data Graph**. This should be a Unify space with Profiles Sync already set up.
166151
2. Click Connect warehouse.
167152
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-
<img src="/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
175158
- **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
178161

179162
5. Test your connection, then click Save.
180163

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+
GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA identifier($retl_schema) TO ROLE identifier($segment_connection_role);
174+
175+
```

0 commit comments

Comments
 (0)