Skip to content

# pg_cron

Use pg_cron to run pgflow workflows on a recurring schedule for time-based automation tasks.

Note

For complete pg_cron documentation including cron expression syntax, job management, and configuration options, see:

- Supabase pg_cron Guide
- pg_cron GitHub Repository

## Basic Usage

Section titled “Basic Usage”

Schedule a workflow to run every 30 minutes:

    SELECT cron.schedule(  'collect-urls',  '*/30 * * * *',  $$    SELECT pgflow.start_flow(      flow_slug => 'collect_urls',      input => jsonb_build_object('sources', ARRAY['news', 'blogs'])    )  $$);

## Processing Recent Records

Section titled “Processing Recent Records”

Query your database and start workflows for matching records. This example processes all orders created in the last 24 hours:

    SELECT cron.schedule(  'process-new-orders',  '0 2 * * *',  -- Daily at 2 AM  $$    SELECT pgflow.start_flow(      flow_slug => 'process_order',      input => jsonb_build_object(        'order_id', order_id,        'customer_email', customer_email,        'total_amount', total_amount      )    )    FROM public.orders    WHERE created_at >= NOW() - INTERVAL '24 hours'      AND status = 'pending'  $$);

This pattern starts one workflow for each matching row, passing the row’s data as input to the workflow.

## Learn More

Section titled “Learn More”
Database Triggers Start workflows automatically when data changes