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: contents/tutorials/supabase-query.md
+28-28Lines changed: 28 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,42 +1,40 @@
1
1
---
2
-
title: How to query Supabase data in PostHog
3
-
date: 2024-08-01
2
+
title: How to sync and query Supabase data in PostHog
3
+
date: 2025-11-11
4
4
author:
5
-
- ian-vanagas
5
+
- ian-vanagas
6
6
tags:
7
-
- data warehouse
7
+
- data warehouse
8
8
---
9
-
10
9
Combining your database and analytics data is a powerful way to understand your users. [Supabase](https://supabase.com/) is a popular choice for handling that app data, as it provides a database, auth, storage, and more all-in-one.
11
10
12
-
Because Supabase is built on Postgres, we can link and query it in PostHog using our data warehouse. This tutorial shows you how to do that and provides some example insights you can create with the data afterward.
11
+
Thanks to modern advances in <RainbowText>enterprise synergy</RainbowText>™, we can link and query your Supabase data in PostHog using our data warehouse. This tutorial shows you how to do that and provides some example insights you can create with the data afterward.
13
12
14
13
## Linking Supabase data to PostHog
15
14
16
-
> **Note:** We currently don't support connections using IPv6, therefore, you will need to enable IPv4 connections to your database. You can find information on how to do this in the [Supabase docs](https://supabase.com/docs/guides/database/connecting-to-postgres#direct-connection).
15
+
> **Note:** We currently don't support connections using IPv6, therefore, you will need to enable IPv4 connections to your database. If you have enabled IPv4 connections, you can [connect directly](https://supabase.com/docs/guides/database/connecting-to-postgres#direct-connection) to your database with a simple connection string. Alternatively, you can use Supabase's [session pooler connection](https://supabase.com/docs/guides/database/connecting-to-postgres#shared-pooler). The shared pooler is IPv4 compatible by default, and it is included in new Supabase projects for free.
16
+
> <ProductScreenshotimageLight="https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/supabase_connection_methods_c6fe1c0f48.png"imageDark="https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/supabase_connection_methods_c6fe1c0f48.png"alt="Supabase data warehouse link setup in PostHog"classes="rounded" />
17
17
18
18
To start, you need both a Supabase and PostHog account. Once you have those, head to PostHog's [data pipeline sources tab](https://us.posthog.com/pipeline/sources) and:
19
19
20
20
1. Click **New source**
21
-
2. Choose the **Postgres** option by clicking **Link.**
22
-
3. Go to your Supabase project settings and under configuration, click **Database.**
23
-
4. Fill out the PostHog data warehouse link fields with your Supabase data.
24
-
1. Under connection parameters, copy host, database name, port, and user (database name in Supabase is just `database` in PostHog)
25
-
26
-

27
-
28
-
2. Enter the password you set for your database.
29
-
3. Choose the schema you want to import. See the Supabase table editor for details on what each one has. `public` is the default, but we also use `auth` and `extensions` later in this tutorial.
30
-
5. Once you add the details, click **Next**.
21
+
2. Choose the **Supabase** option by clicking **Link.**
22
+
3. Go to your Supabase project settings and click **Connect** in the top nav bar.
alt="Supabase data warehouse link setup in PostHog"
36
28
classes="rounded"
37
29
/>
38
30
39
-
6. Choose set up the sync methods, choose the tables you want to include, and click **Import** to start the sync.
31
+
4. Copy the Supabase connection string shown.
32
+
5. Paste the value into the PostHog data warehouse `Connection string` field.
33
+
1. Supabase **will not** include your password in the connection string. You will need to replace their password placeholder manually.
34
+
2. If you've forgotten your Supabase database password, you can [reset it](https://supabase.com/docs/guides/troubleshooting/how-do-i-reset-my-supabase-database-password-oTs5sB).
35
+
6. Fill in the schema name that you want to sync. Typically, this is just `public`.
36
+
7. Click **Next**.
37
+
8. Select the tables you want to include, how you want to sync them, and click **Import** to start syncing.
40
38
41
39
Once it completes, you can then query the data in PostHog.
42
40
@@ -62,15 +60,15 @@ You can use trends to visualize your data. For example, to visualize a count of
62
60
This creates a trend of the count of the objects in your table over time. You can then modify it using filters, visualization options, and breakdowns. For example, to break down by `user_id`, click **Add breakdown**, select the **Data warehouse properties** tab, and then choose `user_id`. To visualize this nicely, you can change the line chart to a total value bar chart.
Linking your Supabase `user` table (under the `auth` schema) enables you to get an overview of user data across both sources. This does require you to add a table prefix like `supabase_` if you already have a Postgres source linked.
71
+
Linking your Supabase `user` table (under the `auth` schema) enables you to get an overview of user data across both sources. This does require you to add a table prefix like `supabase_` if you already have a Postgres source linked.
74
72
75
73
To create this overview, create a new SQL insight that:
76
74
@@ -94,7 +92,7 @@ from sb_users
94
92
left join big_events onbig_events.distinct_id=sb_users.email
95
93
```
96
94
97
-
We could also PostHog person properties or a Supabase table to these by joining more tables to this query.
95
+
We could also PostHog person properties or a Supabase table to these by joining more tables to this query.
98
96
99
97
> **Tip:** You can also set up a join between [PostHog's `persons` table](/docs/data-warehouse/sources/posthog#persons) and your Supabase `users` table. Go to the data warehouse tab, click the three dots next to the `persons` source, and click **Add join**. This enables you to use Supabase `users` data wherever you can use persons.
100
98
> <ProductScreenshotimageLight="https://res.cloudinary.com/dmukukwp6/image/upload/Clean_Shot_2024_08_01_at_14_42_17_2x_21724552d8.png"imageDark="https://res.cloudinary.com/dmukukwp6/image/upload/Clean_Shot_2024_08_01_at_14_42_45_2x_1d6608820e.png"alt="Setting up a join between PostHog's persons table and Supabase users table"classes="rounded" />
@@ -123,7 +121,7 @@ If your payment details were on another table, you could also join that table.
123
121
124
122
### Querying observability stats
125
123
126
-
Supabase also captures observability data we can query if you link the `pg_state_statements` table from the `extensions` schema.
124
+
Supabase also captures observability data we can query if you link the `pg_state_statements` table from the `extensions` schema.
127
125
128
126
An example of a query you could get from this is p95 total execution time along with the median rows read:
129
127
@@ -167,4 +165,6 @@ LIMIT 20
167
165
-[The basics of SQL for analytics](/product-engineers/sql-for-analytics)
168
166
-[How to set up Google Ads reports](/tutorials/google-ads-reports)
0 commit comments