I'm trying to run VACUUM
via SQLAlchemy, and it does not work, because it's in transaction block.
with engine.begin() as connection:
S = orm.session.sessionmaker()()
pd.io.sql.execute('DROP TABLE IF EXISTS %s' % table_name, connection)
df.to_sql(table_name, connection, chunksize=1000)
S.commit()
S.close()
engine.execute('VACUUM')
As you see, I do manually commit and close the session, but still there's an exception:
File "../__init__.py", line 115, in write_file engine.execute('VACUUM')
...
cursor.execute(statement, parameters)
sqlalchemy.exc.InternalError: (psycopg2.InternalError) VACUUM cannot run inside a transaction block
[SQL: 'VACUUM']
I tried all ways, and read through other cases and recommendations, but everyone seems to recommend autocommit
which I can't use in this case.
How can I make VACUUM
work here?