0

I have celery periodic task that need to run postgres VACUUM query after each run, otherwise this task eats a lot of HDD space.

I tried to run VACUUM inside task at the end, but got error:

DatabaseError: VACUUM cannot run inside a transaction block

I tried to apply @transaction.commit_manually decorator and do transaction.commit() before calling VACUUM, but got this error:

TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

Is there way to do VACUUM inside celery task? Or somehow disable for task transaction logic?

ramusus
  • 7,789
  • 5
  • 38
  • 45
  • If it eats up disk space, it probably is because it needs it (disk page splits for mvcc, etc.)... Is it still eating extra space when you run similar transactions multiple times? – Denis de Bernardy Oct 02 '13 at 15:56
  • yes, without VACUUM. This problem about inserting new rows to table with huge text field. That's what my task do. – ramusus Oct 02 '13 at 21:18

1 Answers1

1

In general, you should not usually have to vacuum unless you just did a huge bulk delete. Just make sure autovacuum is running, and is enabled. It will do this in the background and you won't have to worry about it.

Secondly you could fire off a system command to run the vacuumdb command line tool. This would do it in a separate session.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182