Skip to main content
Supabase is an open source Firebase alternative. This page shows how to run real-time analytical queries against a through Supabase using a foreign data wrapper (fdw) to bring aggregated data from your .

Prerequisites

To follow the steps on this page:
  • Create a target with Real-time analytics enabled.

    You need your connection details. This procedure also works for .

Set up your service

To set up a optimized for analytics to receive data from Supabase:
  1. Optimize time-series data in s Time-series data represents how a system, process, or behavior changes over time. Hypertables are tables that help you improve insert and query performance by automatically partitioning your data by time. Connect to your and create a table that will point to a Supabase database:
    When you create a using CREATE TABLE … WITH …, the default partitioning column is automatically the first column with a timestamp data type. Also, creates a columnstore policy that automatically converts your data to the , after an interval equal to the value of the chunk_interval, defined through compress_after in the policy. This columnar format enables fast scanning and aggregation, optimizing performance for analytical workloads while also saving significant storage space. In the conversion, s are compressed by up to 98%, and organized for efficient, large-scale queries. You can customize this policy later using alter_job. However, to change after or created_before, the compression settings, or the the policy is acting on, you must remove the columnstore policy and add a new one. You can also manually convert s in a to the .
  2. Optimize cooling data for analytics is the hybrid row-columnar storage engine in , designed specifically for real-time analytics and powered by time-series data. The advantage of is its ability to seamlessly switch between row-oriented and column-oriented storage. This flexibility enables to deliver the best of both worlds, solving the key challenges in real-time analytics.
  3. Create optimized analytical queries s are designed to make queries on very large datasets run faster. s in use materialized views to continuously, and incrementally refresh a query in the background, so that when you run the query, only the data that has changed needs to be computed, not the entire dataset.
    1. Create a pointing to the Supabase database.
    2. Setup a delay stats comparing origin_time to time.
    3. Setup a view to recieve the data from Supabase.
  4. Add refresh policies for your analytical queries You use start_offset and end_offset to define the time range that the will cover. Assuming that the data is being inserted without any delay, set the start_offset to 5 minutes and the end_offset to 1 minute. This means that the is refreshed every minute, and the refresh covers the last 5 minutes. You set schedule_interval to INTERVAL '1 minute' so the refreshes on your every minute. The data is accessed from Supabase, and the is refreshed every minute in the other side.
    Do the same thing for data inserted with a delay:

Set up a Supabase database

To set up a Supabase database that injects data into your :
  1. Connect a foreign server in Supabase to your
    1. Connect to your Supabase project using Supabase dashboard or psql.
    2. Enable the postgres_fdw extension.
    3. Create a foreign server that points to your . Update the following command with your connection details, then run it in the Supabase database:
  2. Create the user mapping for the foreign server Update the following command with your connection details, the run it in the Supabase database:
  3. Create a foreign table that points to a table in your . This query introduced the following columns:
    • time: with a default value of now(). This is because the time column is used by to optimize data in the .
    • origin_time: store the original timestamp of the data.
    Using both columns, you understand the delay between Supabase (origin_time) and the time the data is inserted into your (time).
  4. Create a foreign table in Supabase
    1. Create a foreign table that matches the signs_per_minute view in your . It represents a top level view of the data.
    2. Create a foreign table that matches the signs_per_minute_delay view in your .

Test the integration

To inject data into your from a Supabase database using a foreign table:
  1. Insert data into your Supabase database Connect to Supabase and run the following query:
  2. Check the data in your Connect to your and run the following query:
    You see something like:
You have successfully integrated Supabase with your .