citusdata / pg_cron

Run periodic jobs in PostgreSQL
PostgreSQL License
2.88k stars 193 forks source link

Is it possible to schedule pg_dump using pg_cron? #338

Open ploef opened 4 months ago

ploef commented 4 months ago

Hi,

Would it be possible to schedule pg_dump with a pg_cron schedule? I tried something like this:

`` SELECT cron.schedule( 'one_time_pg_dump', -- job name '/1 *',
$$pg_dump -U myUser -d mydb -f /tmp/dump$(date +%Y%m%d%H%M%S).sql$$ );

``

But the execution returns the message:

ERROR: syntax error at or near "pg_dump" LINE 1: pg_dump -U myUser -d mydb -f /tmp/dump$(date +%Y%m%... ^

marcoslot commented 4 months ago

Not directly, since it cannot run shell commands. You'd need another extension that lets you run pg_dump via a SQL query.

ploef commented 4 months ago

Thanks for the quick response! Ah that's to bad. I was using pgAgent for that but that's actually way too heavy for what I need. Do you have a suggestion for an extension that I could best use for this?