Skip to content

Commit

Permalink
Add option to disable truncating when vacuuming
Browse files Browse the repository at this point in the history
This allows flexible-freeze to avoid an ACCESS EXCLUSIVE lock on the
table necessary to truncate empty pages off the end of the table.
  • Loading branch information
oschwald committed Jul 3, 2024
1 parent dbf70c6 commit c88aef8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/flexible_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def timestamp():
help="Do VACUUM ANALYZE instead of VACUUM FREEZE ANALYZE")
parser.add_argument("--no-analyze", dest="skip_analyze", action="store_true",
help="Do not do an ANALYZE as part of the VACUUM operation")
parser.add_argument("--no-truncate", dest="skip_truncate", action="store_true",
help="Do not truncate off empty pages as part of the VACUUM operation")
parser.add_argument("--vacuum", dest="vacuum", action="store_true",
help="Do VACUUM ANALYZE instead of VACUUM FREEZE ANALYZE (deprecated option; use --no-freeze instead)")
parser.add_argument("--pause", dest="pause_time", type=int, default=10,
Expand Down Expand Up @@ -310,10 +312,15 @@ def signal_handler(signal, frame):

# if not, vacuum or freeze
exquery = "VACUUM "
options = []
if not args.skip_freeze:
exquery += "FREEZE "
options.append("FREEZE")
if not args.skip_analyze:
exquery += "ANALYZE "
options.append("ANALYZE")
if args.skip_truncate:
options.append("TRUNCATE false")
if options:
exquery += "(%s) " % ", ".join(options)

exquery += '"%s"' % table

Expand All @@ -325,7 +332,7 @@ def signal_handler(signal, frame):
excur.execute(timeout_query)
else:
excur.execute("SET statement_timeout = 0")
print(exquery)
excur.execute(exquery)
except Exception as ex:
_print("VACUUMing %s failed." % table)
Expand Down

0 comments on commit c88aef8

Please sign in to comment.