0

Reading the pg_cron documentation I saw that the examples only execute a command when scheduling a task.

In a StackOverflow post I saw that a user tried to run multiple VACUUM when scheduling the task, but an error occurs.

Is there a way to run VACUUM on multiple tables in sequence using pg_cron? There are about 112 selected tables that must be vacuumed, out of a total of 155, so scheduling a task for each one is not very practical.

Or for example, delete old records from a table and immediately at the end of the process run cron on selected tables?

3
  • A much better approach is to configure autovacuum to be more aggressive so that you don't need to run vacuum manually. Nov 24 at 10:14
  • @a_horse_with_no_name I've already worked with an aggressive configuration for AutoVacuum and AutoAnalyze. The result was a catastrophe, the autovacuum occurred so frequently that the database ended up being unavailable for use, as the tables in my database tend to have several modifications per day.
    – Tom
    Nov 24 at 13:28
  • @Tom, that objection doesn't make much sense, autovacuum doesn't lock out data modifications, and neither schema modifications except when doing it for wraparound; and wraparound vacuums are not controlled by the normal autovac aggressiveness knobs.
    – jjanes
    Nov 24 at 19:48
1

You can vacuum a list of tables in one command.

vacuum FULL pgbench_accounts, pgbench_history, pgbench_branches, pgbench_tellers;

But hopefully you are not really doing FULL, that would almost surely be a mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.