Lytix support BYOC (Bring Your Own Cache) for Postgres. This allows you to own your cache data and query it independently of Lytix.

Integrations

Click below on the integration you’d like to use.

💽 Supabase

You can use a Supabase Postgres database as your cache store. Follow the steps below to get started.

1) Enable pg_cron Extension

First we have to enagble the pg_cron extension for our database. Follow instructions outlined here.

2) Get Your Database URL

You can get your database URL by following these instructions here. To summarize:

  1. Navigate to your project in the Supabase console
  2. Click on the Settings action
  3. Click Database
  4. Copy the ‘Connection String’ value. Remember to add your password here!

Note You need to add ?pooler=true to the end of your database URL. See Github issue here

And you’re all setup getting a new Postgres database.

🐳 Docker

You can also build and host a PSQL docker container to host your cache database. We’ve already created a Dockerfile for you to get started that includes the pg_cron extension.

1) Copy the Repository

First copy the repository from Github.

git clone git@github.com:Lytix-Labs/Lytix-Docker-Cache.git

2) Build the Docker Image

> docker build -t psql-cache-db .

3) Run the Docker Container

> docker run -d \
  --name postgres \
  -v pgdata-cache-1:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=strongpassword \
  -p 5432:5432 \
   lytix-cache-psql

4) Host the Docker Container

You can now host the docker container on a cloud service like AWS, GCP or Azure. After getting a database URL you can follow the steps below to provision the database.

Provision The Postgres Database

Provision script

Prerequisite You will need to download this shell script.

We now can use this shell script to provision a new Postgres database along with setting up our cron job logic.

> export DATABASE_URL=$YOUR_DATABASE_URL
> ./databaset-setup.sh $DATABASE_URL
Creating cache table...
CREATE TABLE
Cache table created successfully.
Creating cache index...
CREATE INDEX
Cache index created successfully.
Creating cache expiration procedure...
CREATE PROCEDURE
CALL
Cache expiration procedure created successfully.
Creating cache expiration cron job...
 schedule
----------
        1
(1 row)

Cache expiration cron job created successfully.
Showing cache expiration cron job...
 jobid | schedule  |       command       | nodename  | nodeport | database | username | active | jobname
-------+-----------+---------------------+-----------+----------+----------+----------+--------+---------
     1 | * * * * * | CALL expire_rows(); | localhost |     5432 | postgres | postgres | t      |
(1 row)

Cache expiration cron job shown successfully.
All done! 🚀. Your PSQL cache has been setup!

Set your Cache Database URL

You can now upload your cache database URL on the Lytix UI here (or here for 🇪🇺).

And you’re all set up! 🎉