Today we're releasing Supabase Cron, a new Postgres Module that makes recurring Jobs simple and intuitive inside your database.
It's designed to work seamlessly with the entire Supabase platform. Create recurring Jobs to run SQL snippets and call database functions, Supabase Edge Functions, and even remote webhooks.
Supabase Cron is built on the powerful pg_cron
extension by the team at Citus Data.
It's a Supabase policy to support existing tools wherever possible, and the Citus Data team have generously licensed their extension with the OSI-compatible PostgreSQL license.
We're very thankful to all the contributors and we look forward to our continued work with the community.
What's a Cron?
Cron is a tool for scheduling recurring tasks that run at specified intervals. These periodic tasks are called “Cron Jobs”. Common use-cases include:
- Maintenance: delete or archive old data.
- Reporting and analytics: save daily or weekly reports for analysis.
- Automation: send periodic emails, like newsletters or reminders.
- Monitoring: perform health checks on your database and log the results.
- Performance: automate vacuuming tables and rebuilding indexes.
Supabase Cron stores the scheduling logic within Postgres and runs your Jobs accordingly while integrating with the rest of the Supabase primitives - Dashboard, Edge Functions, and AI Assistant.
How Do You Use Supabase Cron?
You can create Jobs either via the Dashboard or SQL.
For this post we'll focus on the Dashboard. You can refer to the documentation for SQL.
Within the Dashboard you can define schedules using standard cron syntax and the special pg_cron
seconds syntax for sub-minute schedules or use natural language.
Job Types
You can choose between four types of Jobs based on what you need to execute:
SQL Snippets
Create an inline SQL query or command to run on your database periodically. Use this for tasks like:
- Generating reports.
- Cleaning up stale data.
- Refreshing Materialized Views.
Database Functions
Call a Postgres function. This is useful for workflows, such as:
- Batch processing operations.
- Running periodic maintenance tasks.
- Performing multi-step updates using transactions.
HTTP Requests (webhooks)
Trigger an external HTTP endpoint. Use this for:
- Starting external workflows.
- Syncing data with third-party APIs.
- Sending notifications to external systems.
Supabase Edge Functions
Run a serverless function to execute custom logic. Examples include:
- Creating embeddings.
- Sending automated email updates.
- Fetching external data and storing it in your database.
These options cover a wide range of use cases, helping with everything from database management to external integrations.
Observe and Debug Jobs
Wondering why a Job failed? You can view the history of all Jobs and their logs in the Dashboard. You can see when a Job started, how long it took, and what the result was.
For a deeper dive, you can view Jobs in the Logs Explorer.
Try Supabase Cron today
Getting started is easy:
- Visit the Integrations page in your project.
- Enable the Cron Postgres Module.
- Create your first scheduled Job.
We're looking forward to seeing how you use Supabase Cron to help automate your workflows!