From bf70b22c03ecee8a68b669a82707edc2be1ff85e Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 3 Jul 2024 10:06:31 -0700 Subject: [PATCH] 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. --- scripts/flexible_freeze.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/flexible_freeze.py b/scripts/flexible_freeze.py index 91725d7..56b11ea 100755 --- a/scripts/flexible_freeze.py +++ b/scripts/flexible_freeze.py @@ -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, @@ -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