3

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?

Tom
  • 438
  • 1
  • 6
  • 22

2 Answers2

5

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.

jjanes
  • 42,332
  • 3
  • 44
  • 54
1

VACUUM FULL would lock the table until complete. Use: VACUUM (PARALLEL 3) schema_name.table_name

SkipDigit
  • 21
  • 1