question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pg_cron / seems job never executed

See original GitHub issue

I tried to execute a simples CRON job with pg_cron by following the official tutorial https://supabase.io/blog/2021/03/05/postgres-as-a-cron-server and it’s not working for me.

Where I’m now: I have the pg_cron extension installed by supabase UI; I have the simplest CRON job which looks like

SELECT cron.schedule(
'* * * * *',
$$
  DELETE FROM data
  WHERE id=1
$$
);

if I execute SELECT * FROM cron.job; I will get it in the list of scheduled jobs. But at the end of the day, it never will be executed.

What I already try to do:

  • disable/enable extension
  • create a brand new project and redo steps following the guide

Any ideas on how I can handle this issue?

_Originally posted by @Miruzz in https://github.com/supabase/supabase/discussions/1628_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
dragarciacommented, Jul 2, 2021

Hey everyone 👋, finally found a quick remedy. Do follow this flow when using the pg_cron extension on the dashboard:


0. [OPTIONAL] Drop all scheduled jobs and the pg_cron extension itself

  • This is important if you already have pg_cron enabled and have jobs set
-- repeat as much to clear all jobs
select cron.unschedule(<job id>); 

-- drop the extension
drop extension if exists pg_cron;

1. Enable pg_cron

create extension if not exists pg_cron;

2. [IMPORTANT] Provide the following grants to the user postgres (and in the future any other user that would be using the cron schema). At the baseline, it seems pg_cron uses the postgres user when executing its schedule.

grant usage on schema cron to postgres;
grant all privileges on all tables in schema cron to postgres;

3. Create sample table test_table

CREATE TABLE test_table (
  id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  inserted_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
  updated_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
  name text
);

4. Run a CRON job via pg_cron to add a row to this sample table

select
  cron.schedule(
    'whack-every-minute', 
    '* * * * *', 
    $$
    insert into test_table(name) values ('kek');
    $$
  );

5. Observe that the table test_table is now being populated every minute

select * from test_table;

image

5reactions
dragarciacommented, Jun 1, 2021

Hey guys! Not much at the moment but we are inching towards finding the root cause. Sorry about that. We’ll update you on any major progress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postgresql pg_cron job never executed - DBA Stack Exchange
The problem is that the job is never executed and I there is no error in the error log. Please advice how to...
Read more >
Postgres 13 pg_cron error on RDS that's hard to track down
I'm working on getting pg_partman and pg_cron set up on RDS, but when my pg_cron jobs run, they return this error:
Read more >
Databases: Postgresql pg_cron job never executed - YouTube
Databases: Postgresql pg_cron job never executedHelpful? Please support me on Patreon: https://www.patreon.com/roelvandepaarWith thanks ...
Read more >
pg_cron : Probably the best way to schedule jobs within ...
You can't use pg_cron jobs to schedule a job in seconds interval. For example, you can't schedule a cron job to run every...
Read more >
Cron job troubleshooting guide - Cronitor
Instant alerts when a job fails or never starts ... Cron jobs are run by a system daemon called crond that watches several...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found