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
On this page, you'll learn how to connect your Snowflake data warehouse to Segment.
12
12
13
-
Be sure to log in with a user that has read and write permissions so that Segment can write to your database.
13
+
Log in to Snowflake with a user that has admin privileges to provide Segment Linked Profiles with the necessary permissions below.
14
14
15
15
> info ""
16
16
> Both Linked Events and Linked Profiles support Snowflake.
17
+
17
18
19
+
## Required connection settings within Segment
18
20
19
-
## Getting started
21
+
Segment requires the following settings to connect to your Snowflake warehouse.
20
22
21
-
Use the following steps to set up Snowflake for Linked Profiles.
23
+

22
24
23
-
### Set up Snowflake Credentials and create internal Segment DB
25
+
-**Account ID**: The Snowflake account ID that uniquely identifies your organization account.
26
+
-**Database Name**: 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.
27
+
-**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.
28
+
-**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.
29
+
-**Password**: The password of the user above. This password is referred to as `segment_connection_password` in the script below.
24
30
25
-
Run the SQL below to provide Segment Linked Profiles with the necessary permissions and roles to access the databases, tables, and schemas. These steps involve:
26
-
- Creating a new role and user for Segment Linked Profiles.
27
-
- Granting read-only access to specific databases and schemas that you want to use for Linked Profiles.
28
-
- Granting write access to an internal database that Segment requires for bookkeeping purposes.
29
-
-[Optional] Creating a new warehouse if it does not exist yet. You can skip this step if a warehouse already exists.
30
-
-[Optional] As a best practice, Segment recommends that restrict access to specific databases and schemas.
31
-
- Running the script below to configure the Warehouse permissions.
Segment recommends setting up a new Snowflake user and only giving this user permissions to access the required databases and schemas for Segment Linked Profiles.
34
+
35
+
### Create Segment user and internal database
36
+
37
+
Use the following steps to set up your Snowflake credentials:
40
38
41
-
--UsethesameDBthathasProfilesSyncconfigured. ThisDBisalsousedforSegment's internal bookkeeping. Note: Use this DB in the connection settings on the Segment app.
- Create a new role and user for Segment Linked Profiles.
40
+
- Grant the Segment user access to the warehouse of your choice. If you'd like to create a new warehouse, uncomment the SQL below.
41
+
- Create a new database for Segment Linked Profiles. Segment only requires write access to this one database to create a schema for internal bookkeeping, and to store checkpoint tables for the queries that are executed. Segment recommends creating an empty database for this purpose using the script below. This is also the database you'll be required to specify for the "Database Name" when connecting Snowflake with the Segment app.
43
42
44
-
--UseforeachDByouwantLinkedProfilestoaccess
45
-
SETsegment_linked_database='MARKETING_DB';
43
+
```
44
+
-- ********** SET UP THE FOLLOWING WAREHOUSE PERMISSIONS **********
45
+
-- Edit the following variables
46
+
SET segment_connection_username='SEGMENT_LINKED_USER';
47
+
SET segment_connection_password='my-safe-password';
48
+
SET segment_connection_warehouse='SEGMENT_LINKED_WH';
49
+
SET segment_connection_role='SEGMENT_LINKED_ROLE';
46
50
51
+
-- The DB used for Segment's internal bookkeeping. Note: Use this DB in the connection settings on the Segment app. This is the only DB that Segment requires write access to.
52
+
SET segment_connection_db = 'SEGMENT_LINKED_PROFILES_DB';
47
53
48
54
-- ********** [OPTIONAL] UNCOMMENT THE CODE BELOW IF YOU NEED TO CREATE A NEW WAREHOUSE **********
GRANT ROLE identifier($segment_connection_role) TO USER identifier($segment_connection_username);
83
+
84
+
-- Create and Grant access to a Segment internal DB used for bookkeeping. This is the only DB that Segment requires write access to. This is also the DB you will use in the "Database Name" config while setting up the connection in the Segment app.
85
+
CREATE DATABASE IF NOT EXISTS identifier($segment_connection_db);
86
+
GRANT USAGE ON DATABASE identifier($segment_connection_db) TO ROLE identifier($segment_connection_role);
87
+
GRANT USAGE ON ALL SCHEMAS IN DATABASE identifier($segment_connection_db) TO ROLE identifier($segment_connection_role);
88
+
GRANT CREATE SCHEMA ON DATABASE identifier($segment_connection_db) TO ROLE identifier($segment_connection_role);
89
+
102
90
```
103
91
92
+
### Grant access to other databases
93
+
94
+
Next, give the Segment user **read-only** access to all the other databases you want to use for Linked Profiles.
95
+
96
+
Run the SQL query below for **each** database you want to use for Linked Profiles:
97
+
98
+
```
99
+
100
+
SET segment_connection_role='SEGMENT_LINKED_ROLE';
101
+
102
+
-- Change this for each DB you want to access and re-run the SQL below.
103
+
SET linked_read_only_database='MARKETING_DB';
104
104
105
-
(Optional) [Snowflake Schema Access](https://docs.snowflake.com/en/user-guide/security-access-control-privileges#table-privileges): If you want to restrict access to specific schemas or tables, then run the following command:
105
+
GRANT USAGE ON DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
106
+
GRANT USAGE ON ALL SCHEMAS IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
107
+
GRANT SELECT ON ALL TABLES IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
108
+
GRANT SELECT ON FUTURE TABLES IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
109
+
GRANT SELECT ON ALL VIEWS IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
110
+
GRANT SELECT ON FUTURE VIEWS IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
111
+
GRANT SELECT ON ALL EXTERNAL TABLES IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
112
+
GRANT SELECT ON FUTURE EXTERNAL TABLES IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
113
+
GRANT SELECT ON ALL MATERIALIZED VIEWS IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
114
+
GRANT SELECT ON FUTURE MATERIALIZED VIEWS IN DATABASE identifier($linked_read_only_database) TO ROLE identifier($segment_connection_role);
106
115
107
-
```ts
116
+
```
117
+
118
+
### (Optional) Restrict Snowflake schema access
119
+
120
+
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){:target="_blank”}, run the following commands:
121
+
122
+
```
108
123
-- [Optional] Further restrict access to only specific schemas and tables
109
124
SET db='MY_DB';
110
125
SET schema='MY_DB.MY_SCHEMA_NAME';
126
+
SET segment_connection_role='SEGMENT_LINKED_ROLE';
### (If applicable) Add table permissions if Reverse ETL has ever run in your database
141
+
### (If applicable) Update user acccess for Segment Reverse ETL schema
142
+
143
+
> warning ""
144
+
> 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.
123
145
124
-
If Reverse ETL has ever run in the database you are configuring as the Segment Internal DB, a Segment-managed schema is created and a new user is added. Add the Snowflake table permissions by running the following command.
146
+
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.
147
+
148
+
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.
125
149
126
-
```ts
150
+
Add the Snowflake table permissions by running the following commands:
151
+
152
+
```
127
153
-- 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.
128
154
129
155
SET retl_schema = concat($segment_internal_database,'.__segment_reverse_etl');
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. This command should succeed and you should be able to view the respective table.
167
+
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.
0 commit comments