do a
VACUUM FULL
if you want to run this on python you need to set autocommit = True otherwise it will not work.
conn.set_session(readonly=True, autocommit=True) sql = """ VACUUM FULL """ cur.execute(sql) conn.commit() conn.set_session(readonly=True, autocommit=False)