HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Use pg_cron to run VACUUM on multiple tables

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablesvacuummultiplepg_cronuserun

Problem

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?

Solution

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.

Code Snippets

vacuum FULL pgbench_accounts, pgbench_history, pgbench_branches, pgbench_tellers;

Context

StackExchange Database Administrators Q#303052, answer score: 4

Revisions (0)

No revisions yet.