Amended patch attached after a few Perl-related comments I got on
private mail. Instead of
$exc_save !~ /^$timeout_exception.*/
I've updated to:
$exc_save !~ /^\Q$timeout_exception\E/
i.e. don't do an unnecessary wildcard match at the end, and disable
metachar interpretation in the substituted range.
Still needs applying to pg9.6 and pg10.