Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 8 min read How-to mediumAdept

How to fix missing table errors in pg_cron

pg_cron stores scheduled jobs as raw SQL text, separate from Postgres' system catalogs, so dropping a table leaves jobs that fail every run with "relation does not exist" and fill cron.job_run_details with errors. Manual unscheduling, defensive DO blocks and cleanup jobs all leave gaps. A roughly 30-line PL/pgSQL event trigger on sql_drop closes them: it calls pg_event_trigger_dropped_objects() and unschedules any cron.job whose command mentions the dropped table name. The post also lists operational practices, such as explicit statement_timeout, setting search_path, and purging run history, and says when Airflow or Inngest fit better than pg_cron.

Assumes: PostgreSQL basicsPL/pgSQL functionscron syntax

Related posts

  • Run Scheduled and Recurring Tasks with Cron

    Railway mediumAdept

    Cron runs commands on time-based schedules but keeps no job history, has no retries and does no concurrency control, so reliability depends on the job itself. The guide covers the five-field schedule syntax, including the day-of-month/weekday OR pitfall and timezone/DST issues, and recommends idempotent upserts, structured start/success/error logs, explicit connection cleanup, and Postgres advisory locks to prevent overlapping runs. On Railway, cron triggers a service's start command in UTC with a 5-minute minimum interval and a single active execution. A process left alive by open handles or pending promises causes later runs to be skipped.

  • Postgres as a CRON Server

    Supabase mediumAdept

    Postgres can act as a cron server by combining the pg_cron extension for scheduling with the pgsql-http extension for outbound HTTP calls, letting a scheduled SQL statement POST to a webhook every minute. The walkthrough covers enabling both extensions, granting cron schema access to non-superuser roles, cron syntax, and inspecting or unscheduling jobs via cron.job and cron.job_run_details. pg_cron runs jobs in background workers so slow endpoints don't block core Postgres, but setting http.timeout_msec to fail fast is still recommended. Suggested uses include batching welcome emails, aggregating data and deleting old rows.

  • Your Neon Functions can now run on a schedule

    Neon mediumAdept

    Neon Function Triggers let Neon invoke a deployed Node.js function on a cron schedule. Because the timer lives outside the Postgres compute, scheduled jobs keep working with scale to zero, unlike pg_cron, which only runs while the compute is up and can only execute SQL. Triggers are branch-scoped, and child branches inherit their parent's triggers in a disabled state, so branching production doesn't double-fire jobs. A worked example uses a Hono handler that verifies the X-Neon-Trigger-Invocation-Id header, reads scheduled_at from the request body, and uses ON CONFLICT DO NOTHING to stay idempotent, plus the API call that creates a 15-minute schedule.

  • Postgres Event Triggers Are Now Supported in Neon

    Neon mediumAdept

    Neon now supports Postgres event triggers through the neon_superuser role, and they behave exactly as in vanilla Postgres. Unlike row-level triggers, event triggers fire on DDL commands such as CREATE, ALTER and DROP. They can audit schema changes on ddl_command_end, automate metadata updates or alerts, and feed schema changes to sync engines like Zero via pg_event_trigger_ddl_commands(). Short examples show blocking DROP TABLE for non-admin roles and cleaning up orphaned pg_cron jobs on sql_drop using pg_event_trigger_dropped_objects().

  • Post mortem on Linear incident from Jan 24th, 2024

    Linear mediumAdept

    A database migration using `TRUNCATE TABLE ... CASCADE` on two new, unused tables silently wiped every production table with foreign keys to them, including issue and document descriptions, comments, notifications and reactions. Layered caching in Linear's sync engine hid the loss for about 30 minutes, and sync-lag warnings were excluded from alerting. Because point-in-time recovery had never been tested, the team restored a full backup from hours earlier, causing an hour of downtime and five hours of lost changes. They then replayed sync-engine action logs per workspace, with dry-runs first, recovering over 99% of data within 36 hours; follow-ups include revoking TRUNCATE privileges, linting migrations, PITR tooling and a read-only mode.

The quest for software engineering knowledge.

Look:
Layout: