# Postgres as a CRON Server

[Supabase](https://yomu.fyi/company/supabase) · Paul Copplestone · Mar 5, 2021

**Type:** Tutorial

## Summary

Postgres databases can schedule and execute external webhook calls periodically by combining the pg\_cron and pgsql-http extensions. When configured, pg\_cron schedules recurring tasks using standard cron syntax directly inside the database engine. In conjunction, the pgsql-http extension dispatches HTTP requests such as GET, POST, PATCH, and DELETE to external endpoints within SQL queries. Because pg\_cron relies on background workers that start one process per server loop iteration, scheduled jobs do not interfere with core postmaster tasks or external client connections. Administrators can monitor job status, review execution logs, and unschedule active tasks directly through dedicated cron schema tables and helper functions.

## Context

A Supabase user needed to trigger webhooks periodically before Supabase released its Functions feature, prompting an investigation into whether standard Postgres could manage scheduled external HTTP requests.

## Approach / What changed

Enable the pg\_cron and pgsql-http extensions in Postgres, grant cron schema permissions to non-superuser roles, and schedule periodic queries containing http\_post calls with cron.schedule.

## Takeaways

- Non-superuser roles require explicit USAGE on schema cron and privileges on its underlying tables, or scheduled jobs will fail to run.
- pg\_cron executes tasks via background workers that start one process per ServerLoop iteration, preventing slow HTTP requests from blocking core postmaster connection handling.
- Cron jobs and execution histories can be inspected using cron.job and cron.job\_run\_details, and active tasks can be cancelled using cron.unschedule.

**Tags:** [Postgres](https://yomu.fyi/topic/postgres), [REST APIs](https://yomu.fyi/topic/rest-api)

[Read original post](https://supabase.com/blog/postgres-as-a-cron-server)
