Psycopg2: how to execute a postgresql vacuum request in python script

I am using Python with psycopg2 and I am trying to run the full VACUUM in a python script. The problem is that when I try to run the VACUUM command in my code, I get the following error:

psycopg2.InternalError: VACUUM cannot work inside a transaction block

The line I'm trying to execute is:

sql = "vacuum full table_name;"

cur.execute (SQL)

How to resolve this error?

+6
source share
1 answer

Psycopg2 starts a new transaction for every call to .execute ().

Open the automatic connection for vacuum processing.

http://initd.org/psycopg/docs/connection.html#connection.autocommit

+5
source

Source: https://habr.com/ru/post/987106/


All Articles