Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional per-table lock timeout #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions scripts/flexible_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def timestamp():
parser.add_argument("--enforce-time", dest="enforcetime", action="store_true",
help="enforce time limit by terminating vacuum")
parser.add_argument("-l", "--log", dest="logfile")
parser.add_argument("--lock-timeout", type=int, dest="lock_timeout",
help="If VACUUM can't get a lock on a table after this many milliseconds, give up and move on to the next table (prevents VACUUM from waiting on existing autovacuums)")
parser.add_argument("-v", "--verbose", action="store_true",
dest="verbose")
parser.add_argument("--debug", action="store_true",
Expand Down Expand Up @@ -325,16 +327,21 @@ def signal_handler(signal, frame):
excur.execute(timeout_query)
else:
excur.execute("SET statement_timeout = 0")


if args.lock_timeout:
excur.execute("SET lock_timeout = {}".format(args.lock_timeout))

excur.execute(exquery)
except Exception as ex:
_print("VACUUMing %s failed." % table)
_print(str(ex))
if time.time() >= halt_time:
verbose_print("halted flexible_freeze due to enforced time limit")
strex = str(ex).rstrip()
if strex == 'canceling statement due to lock timeout':
_print("VACUUM failed to lock table %table after {locktime} ms. Skipping to the next table...".format(table=table, locktime=args.lock_timeout))
else:
_print("VACUUMING %s failed." % table[0])
_print(str(ex))
_print(strex)

if time.time() >= halt_time:
verbose_print("halted flexible_freeze due to enforced time limit")
sys.exit(1)

time.sleep(args.pause_time)
Expand Down