Skip to content

Commit c88aef8

Browse files
committed
Add option to disable truncating when vacuuming
This allows flexible-freeze to avoid an ACCESS EXCLUSIVE lock on the table necessary to truncate empty pages off the end of the table.
1 parent dbf70c6 commit c88aef8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/flexible_freeze.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def timestamp():
4545
help="Do VACUUM ANALYZE instead of VACUUM FREEZE ANALYZE")
4646
parser.add_argument("--no-analyze", dest="skip_analyze", action="store_true",
4747
help="Do not do an ANALYZE as part of the VACUUM operation")
48+
parser.add_argument("--no-truncate", dest="skip_truncate", action="store_true",
49+
help="Do not truncate off empty pages as part of the VACUUM operation")
4850
parser.add_argument("--vacuum", dest="vacuum", action="store_true",
4951
help="Do VACUUM ANALYZE instead of VACUUM FREEZE ANALYZE (deprecated option; use --no-freeze instead)")
5052
parser.add_argument("--pause", dest="pause_time", type=int, default=10,
@@ -310,10 +312,15 @@ def signal_handler(signal, frame):
310312

311313
# if not, vacuum or freeze
312314
exquery = "VACUUM "
315+
options = []
313316
if not args.skip_freeze:
314-
exquery += "FREEZE "
317+
options.append("FREEZE")
315318
if not args.skip_analyze:
316-
exquery += "ANALYZE "
319+
options.append("ANALYZE")
320+
if args.skip_truncate:
321+
options.append("TRUNCATE false")
322+
if options:
323+
exquery += "(%s) " % ", ".join(options)
317324

318325
exquery += '"%s"' % table
319326

@@ -325,7 +332,7 @@ def signal_handler(signal, frame):
325332
excur.execute(timeout_query)
326333
else:
327334
excur.execute("SET statement_timeout = 0")
328-
335+
print(exquery)
329336
excur.execute(exquery)
330337
except Exception as ex:
331338
_print("VACUUMing %s failed." % table)

0 commit comments

Comments
 (0)